GetGraphqlApi TCL Example
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
}
CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "GetGraphqlApi"
set sbResponseBody [new_CkStringBuilder]
set success [CkRest_FullRequestNoBodySb $rest "GET" "/v1/apis/{apiId}" $sbResponseBody]
if {$success != 1} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
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_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_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp