Chilkat Online Tools

ListGraphqlApis 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
}

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

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/v1/apis" $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 nextToken [CkJsonObject_stringOf $jResp "nextToken"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "graphqlApis"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set apiId [CkJsonObject_stringOf $jResp "graphqlApis[i].apiId"]
    set arn [CkJsonObject_stringOf $jResp "graphqlApis[i].arn"]
    set authenticationType [CkJsonObject_stringOf $jResp "graphqlApis[i].authenticationType"]
    set AuthorizerResultTtlInSeconds [CkJsonObject_IntOf $jResp "graphqlApis[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds"]
    set AuthorizerUri [CkJsonObject_stringOf $jResp "graphqlApis[i].lambdaAuthorizerConfig.authorizerUri"]
    set IdentityValidationExpression [CkJsonObject_stringOf $jResp "graphqlApis[i].lambdaAuthorizerConfig.identityValidationExpression"]
    set CloudWatchLogsRoleArn [CkJsonObject_stringOf $jResp "graphqlApis[i].logConfig.cloudWatchLogsRoleArn"]
    set ExcludeVerboseContent [CkJsonObject_IntOf $jResp "graphqlApis[i].logConfig.excludeVerboseContent"]
    set FieldLogLevel [CkJsonObject_stringOf $jResp "graphqlApis[i].logConfig.fieldLogLevel"]
    set name [CkJsonObject_stringOf $jResp "graphqlApis[i].name"]
    set AuthTTL [CkJsonObject_IntOf $jResp "graphqlApis[i].openIDConnectConfig.authTTL"]
    set ClientId [CkJsonObject_stringOf $jResp "graphqlApis[i].openIDConnectConfig.clientId"]
    set IatTTL [CkJsonObject_IntOf $jResp "graphqlApis[i].openIDConnectConfig.iatTTL"]
    set Issuer [CkJsonObject_stringOf $jResp "graphqlApis[i].openIDConnectConfig.issuer"]
    set v_String [CkJsonObject_stringOf $jResp "graphqlApis[i].tags.string"]
    set urisString [CkJsonObject_stringOf $jResp "graphqlApis[i].uris.string"]
    set AppIdClientRegex [CkJsonObject_stringOf $jResp "graphqlApis[i].userPoolConfig.appIdClientRegex"]
    set AwsRegion [CkJsonObject_stringOf $jResp "graphqlApis[i].userPoolConfig.awsRegion"]
    set DefaultAction [CkJsonObject_stringOf $jResp "graphqlApis[i].userPoolConfig.defaultAction"]
    set UserPoolId [CkJsonObject_stringOf $jResp "graphqlApis[i].userPoolConfig.userPoolId"]
    set wafWebAclArn [CkJsonObject_stringOf $jResp "graphqlApis[i].wafWebAclArn"]
    set xrayEnabled [CkJsonObject_IntOf $jResp "graphqlApis[i].xrayEnabled"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "graphqlApis[i].additionalAuthenticationProviders"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set authenticationType [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].authenticationType"]
        set lambdaAuthorizerConfigAuthorizerResultTtlInSeconds [CkJsonObject_IntOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.authorizerResultTtlInSeconds"]
        set lambdaAuthorizerConfigAuthorizerUri [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.authorizerUri"]
        set lambdaAuthorizerConfigIdentityValidationExpression [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.identityValidationExpression"]
        set openIDConnectConfigAuthTTL [CkJsonObject_IntOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.authTTL"]
        set openIDConnectConfigClientId [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.clientId"]
        set openIDConnectConfigIatTTL [CkJsonObject_IntOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.iatTTL"]
        set openIDConnectConfigIssuer [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.issuer"]
        set userPoolConfigAppIdClientRegex [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.appIdClientRegex"]
        set userPoolConfigAwsRegion [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.awsRegion"]
        set userPoolConfigUserPoolId [CkJsonObject_stringOf $jResp "graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.userPoolId"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

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

# {
#   "graphqlApis": [
#     {
#       "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
#     }
#   ],
#   "nextToken": "string"
# }

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