Chilkat Online Tools

UpdateDataSource Foxpro Example

AWS AppSync

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcDataSourceArn
LOCAL lcDescription
LOCAL lcAwsRegion
LOCAL lnBaseTableTTL
LOCAL lcDeltaSyncTableName
LOCAL lnDeltaSyncTableTTL
LOCAL lcTableName
LOCAL lnUseCallerCredentials
LOCAL lnVersioned
LOCAL lcElasticsearchConfigAwsRegion
LOCAL lcEndpoint
LOCAL lcAuthorizationType
LOCAL lcSigningRegion
LOCAL lcSigningServiceName
LOCAL lcHttpConfigEndpoint
LOCAL lcLambdaFunctionArn
LOCAL lcName
LOCAL lcOpenSearchServiceConfigAwsRegion
LOCAL lcOpenSearchServiceConfigEndpoint
LOCAL lcRdsHttpEndpointConfigAwsRegion
LOCAL lcAwsSecretStoreArn
LOCAL lcDatabaseName
LOCAL lcDbClusterIdentifier
LOCAL lcSchema
LOCAL lcRelationalDatabaseSourceType
LOCAL lcServiceRoleArn
LOCAL lcV_Type

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "AWS_SECRET_KEY"

* Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "appsync"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://appsync.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("appsync.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

* The following code creates the JSON request body.
* The JSON created by this code is shown below.

* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("description","string")
loJson.UpdateString("dynamodbConfig.awsRegion","string")
loJson.UpdateInt("dynamodbConfig.deltaSyncConfig.baseTableTTL",123)
loJson.UpdateString("dynamodbConfig.deltaSyncConfig.deltaSyncTableName","string")
loJson.UpdateInt("dynamodbConfig.deltaSyncConfig.deltaSyncTableTTL",123)
loJson.UpdateString("dynamodbConfig.tableName","string")
loJson.UpdateInt("dynamodbConfig.useCallerCredentials",123)
loJson.UpdateInt("dynamodbConfig.versioned",123)
loJson.UpdateString("elasticsearchConfig.awsRegion","string")
loJson.UpdateString("elasticsearchConfig.endpoint","string")
loJson.UpdateString("httpConfig.authorizationConfig.authorizationType","string")
loJson.UpdateString("httpConfig.authorizationConfig.awsIamConfig.signingRegion","string")
loJson.UpdateString("httpConfig.authorizationConfig.awsIamConfig.signingServiceName","string")
loJson.UpdateString("httpConfig.endpoint","string")
loJson.UpdateString("lambdaConfig.lambdaFunctionArn","string")
loJson.UpdateString("openSearchServiceConfig.awsRegion","string")
loJson.UpdateString("openSearchServiceConfig.endpoint","string")
loJson.UpdateString("relationalDatabaseConfig.rdsHttpEndpointConfig.awsRegion","string")
loJson.UpdateString("relationalDatabaseConfig.rdsHttpEndpointConfig.awsSecretStoreArn","string")
loJson.UpdateString("relationalDatabaseConfig.rdsHttpEndpointConfig.databaseName","string")
loJson.UpdateString("relationalDatabaseConfig.rdsHttpEndpointConfig.dbClusterIdentifier","string")
loJson.UpdateString("relationalDatabaseConfig.rdsHttpEndpointConfig.schema","string")
loJson.UpdateString("relationalDatabaseConfig.relationalDatabaseSourceType","string")
loJson.UpdateString("serviceRoleArn","string")
loJson.UpdateString("type","string")

* The JSON request body created by the above code:

* {
*   "description": "string",
*   "dynamodbConfig": {
*     "awsRegion": "string",
*     "deltaSyncConfig": {
*       "baseTableTTL": number,
*       "deltaSyncTableName": "string",
*       "deltaSyncTableTTL": number
*     },
*     "tableName": "string",
*     "useCallerCredentials": boolean,
*     "versioned": boolean
*   },
*   "elasticsearchConfig": {
*     "awsRegion": "string",
*     "endpoint": "string"
*   },
*   "httpConfig": {
*     "authorizationConfig": {
*       "authorizationType": "string",
*       "awsIamConfig": {
*         "signingRegion": "string",
*         "signingServiceName": "string"
*       }
*     },
*     "endpoint": "string"
*   },
*   "lambdaConfig": {
*     "lambdaFunctionArn": "string"
*   },
*   "openSearchServiceConfig": {
*     "awsRegion": "string",
*     "endpoint": "string"
*   },
*   "relationalDatabaseConfig": {
*     "rdsHttpEndpointConfig": {
*       "awsRegion": "string",
*       "awsSecretStoreArn": "string",
*       "databaseName": "string",
*       "dbClusterIdentifier": "string",
*       "schema": "string"
*     },
*     "relationalDatabaseSourceType": "string"
*   },
*   "serviceRoleArn": "string",
*   "type": "string"
* }

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","UpdateDataSource")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/v1/apis/{apiId}/datasources/{name}",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)

* The following code parses the JSON response.
* A sample JSON response is shown below the sample code.

* Use this online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON

lcDataSourceArn = loJResp.StringOf("dataSource.dataSourceArn")
lcDescription = loJResp.StringOf("dataSource.description")
lcAwsRegion = loJResp.StringOf("dataSource.dynamodbConfig.awsRegion")
lnBaseTableTTL = loJResp.IntOf("dataSource.dynamodbConfig.deltaSyncConfig.baseTableTTL")
lcDeltaSyncTableName = loJResp.StringOf("dataSource.dynamodbConfig.deltaSyncConfig.deltaSyncTableName")
lnDeltaSyncTableTTL = loJResp.IntOf("dataSource.dynamodbConfig.deltaSyncConfig.deltaSyncTableTTL")
lcTableName = loJResp.StringOf("dataSource.dynamodbConfig.tableName")
lnUseCallerCredentials = loJResp.IntOf("dataSource.dynamodbConfig.useCallerCredentials")
lnVersioned = loJResp.IntOf("dataSource.dynamodbConfig.versioned")
lcElasticsearchConfigAwsRegion = loJResp.StringOf("dataSource.elasticsearchConfig.awsRegion")
lcEndpoint = loJResp.StringOf("dataSource.elasticsearchConfig.endpoint")
lcAuthorizationType = loJResp.StringOf("dataSource.httpConfig.authorizationConfig.authorizationType")
lcSigningRegion = loJResp.StringOf("dataSource.httpConfig.authorizationConfig.awsIamConfig.signingRegion")
lcSigningServiceName = loJResp.StringOf("dataSource.httpConfig.authorizationConfig.awsIamConfig.signingServiceName")
lcHttpConfigEndpoint = loJResp.StringOf("dataSource.httpConfig.endpoint")
lcLambdaFunctionArn = loJResp.StringOf("dataSource.lambdaConfig.lambdaFunctionArn")
lcName = loJResp.StringOf("dataSource.name")
lcOpenSearchServiceConfigAwsRegion = loJResp.StringOf("dataSource.openSearchServiceConfig.awsRegion")
lcOpenSearchServiceConfigEndpoint = loJResp.StringOf("dataSource.openSearchServiceConfig.endpoint")
lcRdsHttpEndpointConfigAwsRegion = loJResp.StringOf("dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.awsRegion")
lcAwsSecretStoreArn = loJResp.StringOf("dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.awsSecretStoreArn")
lcDatabaseName = loJResp.StringOf("dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.databaseName")
lcDbClusterIdentifier = loJResp.StringOf("dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.dbClusterIdentifier")
lcSchema = loJResp.StringOf("dataSource.relationalDatabaseConfig.rdsHttpEndpointConfig.schema")
lcRelationalDatabaseSourceType = loJResp.StringOf("dataSource.relationalDatabaseConfig.relationalDatabaseSourceType")
lcServiceRoleArn = loJResp.StringOf("dataSource.serviceRoleArn")
lcV_Type = loJResp.StringOf("dataSource.type")

* A sample JSON response body parsed by the above code:

* {
*   "dataSource": {
*     "dataSourceArn": "string",
*     "description": "string",
*     "dynamodbConfig": {
*       "awsRegion": "string",
*       "deltaSyncConfig": {
*         "baseTableTTL": number,
*         "deltaSyncTableName": "string",
*         "deltaSyncTableTTL": number
*       },
*       "tableName": "string",
*       "useCallerCredentials": boolean,
*       "versioned": boolean
*     },
*     "elasticsearchConfig": {
*       "awsRegion": "string",
*       "endpoint": "string"
*     },
*     "httpConfig": {
*       "authorizationConfig": {
*         "authorizationType": "string",
*         "awsIamConfig": {
*           "signingRegion": "string",
*           "signingServiceName": "string"
*         }
*       },
*       "endpoint": "string"
*     },
*     "lambdaConfig": {
*       "lambdaFunctionArn": "string"
*     },
*     "name": "string",
*     "openSearchServiceConfig": {
*       "awsRegion": "string",
*       "endpoint": "string"
*     },
*     "relationalDatabaseConfig": {
*       "rdsHttpEndpointConfig": {
*         "awsRegion": "string",
*         "awsSecretStoreArn": "string",
*         "databaseName": "string",
*         "dbClusterIdentifier": "string",
*         "schema": "string"
*       },
*       "relationalDatabaseSourceType": "string"
*     },
*     "serviceRoleArn": "string",
*     "type": "string"
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp