Chilkat Online Tools

UpdateGraphqlApi TCL Example

AWS AppSync

load ./chilkat.dll

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

set rest [new_CkRest]

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "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.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "appsync"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://appsync.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "appsync.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

# 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

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].authenticationType" "string"
CkJsonObject_UpdateInt $json "additionalAuthenticationProviders[0].lambdaAuthorizerConfig.authorizerResultTtlInSeconds" 123
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].lambdaAuthorizerConfig.authorizerUri" "string"
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].lambdaAuthorizerConfig.identityValidationExpression" "string"
CkJsonObject_UpdateInt $json "additionalAuthenticationProviders[0].openIDConnectConfig.authTTL" 123
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].openIDConnectConfig.clientId" "string"
CkJsonObject_UpdateInt $json "additionalAuthenticationProviders[0].openIDConnectConfig.iatTTL" 123
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].openIDConnectConfig.issuer" "string"
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].userPoolConfig.appIdClientRegex" "string"
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].userPoolConfig.awsRegion" "string"
CkJsonObject_UpdateString $json "additionalAuthenticationProviders[0].userPoolConfig.userPoolId" "string"
CkJsonObject_UpdateString $json "authenticationType" "string"
CkJsonObject_UpdateInt $json "lambdaAuthorizerConfig.authorizerResultTtlInSeconds" 123
CkJsonObject_UpdateString $json "lambdaAuthorizerConfig.authorizerUri" "string"
CkJsonObject_UpdateString $json "lambdaAuthorizerConfig.identityValidationExpression" "string"
CkJsonObject_UpdateString $json "logConfig.cloudWatchLogsRoleArn" "string"
CkJsonObject_UpdateInt $json "logConfig.excludeVerboseContent" 123
CkJsonObject_UpdateString $json "logConfig.fieldLogLevel" "string"
CkJsonObject_UpdateString $json "name" "string"
CkJsonObject_UpdateInt $json "openIDConnectConfig.authTTL" 123
CkJsonObject_UpdateString $json "openIDConnectConfig.clientId" "string"
CkJsonObject_UpdateInt $json "openIDConnectConfig.iatTTL" 123
CkJsonObject_UpdateString $json "openIDConnectConfig.issuer" "string"
CkJsonObject_UpdateString $json "userPoolConfig.appIdClientRegex" "string"
CkJsonObject_UpdateString $json "userPoolConfig.awsRegion" "string"
CkJsonObject_UpdateString $json "userPoolConfig.defaultAction" "string"
CkJsonObject_UpdateString $json "userPoolConfig.userPoolId" "string"
CkJsonObject_UpdateInt $json "xrayEnabled" 123

# The JSON request body created by the above code:

# {
#   "additionalAuthenticationProviders": [
#     {
#       "authenticationType": "string",
#       "lambdaAuthorizerConfig": {
#         "authorizerResultTtlInSeconds": number,
#         "authorizerUri": "string",
#         "identityValidationExpression": "string"
#       },
#       "openIDConnectConfig": {
#         "authTTL": number,
#         "clientId": "string",
#         "iatTTL": number,
#         "issuer": "string"
#       },
#       "userPoolConfig": {
#         "appIdClientRegex": "string",
#         "awsRegion": "string",
#         "userPoolId": "string"
#       }
#     }
#   ],
#   "authenticationType": "string",
#   "lambdaAuthorizerConfig": {
#     "authorizerResultTtlInSeconds": number,
#     "authorizerUri": "string",
#     "identityValidationExpression": "string"
#   },
#   "logConfig": {
#     "cloudWatchLogsRoleArn": "string",
#     "excludeVerboseContent": boolean,
#     "fieldLogLevel": "string"
#   },
#   "name": "string",
#   "openIDConnectConfig": {
#     "authTTL": number,
#     "clientId": "string",
#     "iatTTL": number,
#     "issuer": "string"
#   },
#   "userPoolConfig": {
#     "appIdClientRegex": "string",
#     "awsRegion": "string",
#     "defaultAction": "string",
#     "userPoolId": "string"
#   },
#   "xrayEnabled": boolean
# }

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "UpdateGraphqlApi"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/v1/apis/{apiId}" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody

# 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

set ApiId [CkJsonObject_stringOf $jResp "graphqlApi.apiId"]
set Arn [CkJsonObject_stringOf $jResp "graphqlApi.arn"]
set AuthenticationType [CkJsonObject_stringOf $jResp "graphqlApi.authenticationType"]
set AuthorizerResultTtlInSeconds [CkJsonObject_IntOf $jResp "graphqlApi.lambdaAuthorizerConfig.authorizerResultTtlInSeconds"]
set AuthorizerUri [CkJsonObject_stringOf $jResp "graphqlApi.lambdaAuthorizerConfig.authorizerUri"]
set IdentityValidationExpression [CkJsonObject_stringOf $jResp "graphqlApi.lambdaAuthorizerConfig.identityValidationExpression"]
set CloudWatchLogsRoleArn [CkJsonObject_stringOf $jResp "graphqlApi.logConfig.cloudWatchLogsRoleArn"]
set ExcludeVerboseContent [CkJsonObject_IntOf $jResp "graphqlApi.logConfig.excludeVerboseContent"]
set FieldLogLevel [CkJsonObject_stringOf $jResp "graphqlApi.logConfig.fieldLogLevel"]
set Name [CkJsonObject_stringOf $jResp "graphqlApi.name"]
set AuthTTL [CkJsonObject_IntOf $jResp "graphqlApi.openIDConnectConfig.authTTL"]
set ClientId [CkJsonObject_stringOf $jResp "graphqlApi.openIDConnectConfig.clientId"]
set IatTTL [CkJsonObject_IntOf $jResp "graphqlApi.openIDConnectConfig.iatTTL"]
set Issuer [CkJsonObject_stringOf $jResp "graphqlApi.openIDConnectConfig.issuer"]
set v_String [CkJsonObject_stringOf $jResp "graphqlApi.tags.string"]
set UrisString [CkJsonObject_stringOf $jResp "graphqlApi.uris.string"]
set AppIdClientRegex [CkJsonObject_stringOf $jResp "graphqlApi.userPoolConfig.appIdClientRegex"]
set AwsRegion [CkJsonObject_stringOf $jResp "graphqlApi.userPoolConfig.awsRegion"]
set DefaultAction [CkJsonObject_stringOf $jResp "graphqlApi.userPoolConfig.defaultAction"]
set UserPoolId [CkJsonObject_stringOf $jResp "graphqlApi.userPoolConfig.userPoolId"]
set WafWebAclArn [CkJsonObject_stringOf $jResp "graphqlApi.wafWebAclArn"]
set XrayEnabled [CkJsonObject_IntOf $jResp "graphqlApi.xrayEnabled"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "graphqlApi.additionalAuthenticationProviders"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set authenticationType [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].authenticationType"]
    set lambdaAuthorizerConfigAuthorizerResultTtlInSeconds [CkJsonObject_IntOf $jResp "graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds"]
    set lambdaAuthorizerConfigAuthorizerUri [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerUri"]
    set lambdaAuthorizerConfigIdentityValidationExpression [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.identityValidationExpression"]
    set openIDConnectConfigAuthTTL [CkJsonObject_IntOf $jResp "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.authTTL"]
    set openIDConnectConfigClientId [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.clientId"]
    set openIDConnectConfigIatTTL [CkJsonObject_IntOf $jResp "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.iatTTL"]
    set openIDConnectConfigIssuer [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.issuer"]
    set userPoolConfigAppIdClientRegex [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.appIdClientRegex"]
    set userPoolConfigAwsRegion [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.awsRegion"]
    set userPoolConfigUserPoolId [CkJsonObject_stringOf $jResp "graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.userPoolId"]
    set i [expr $i + 1]
}

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

# {
#   "graphqlApi": {
#     "additionalAuthenticationProviders": [
#       {
#         "authenticationType": "string",
#         "lambdaAuthorizerConfig": {
#           "authorizerResultTtlInSeconds": number,
#           "authorizerUri": "string",
#           "identityValidationExpression": "string"
#         },
#         "openIDConnectConfig": {
#           "authTTL": number,
#           "clientId": "string",
#           "iatTTL": number,
#           "issuer": "string"
#         },
#         "userPoolConfig": {
#           "appIdClientRegex": "string",
#           "awsRegion": "string",
#           "userPoolId": "string"
#         }
#       }
#     ],
#     "apiId": "string",
#     "arn": "string",
#     "authenticationType": "string",
#     "lambdaAuthorizerConfig": {
#       "authorizerResultTtlInSeconds": number,
#       "authorizerUri": "string",
#       "identityValidationExpression": "string"
#     },
#     "logConfig": {
#       "cloudWatchLogsRoleArn": "string",
#       "excludeVerboseContent": boolean,
#       "fieldLogLevel": "string"
#     },
#     "name": "string",
#     "openIDConnectConfig": {
#       "authTTL": number,
#       "clientId": "string",
#       "iatTTL": number,
#       "issuer": "string"
#     },
#     "tags": {
#       "string": "string"
#     },
#     "uris": {
#       "string": "string"
#     },
#     "userPoolConfig": {
#       "appIdClientRegex": "string",
#       "awsRegion": "string",
#       "defaultAction": "string",
#       "userPoolId": "string"
#     },
#     "wafWebAclArn": "string",
#     "xrayEnabled": boolean
#   }
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp