ListGraphqlApis PureBasic Example
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
authAws.i = CkAuthAws::ckCreate()
If authAws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
CkAuthAws::setCkSecretKey(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::setCkRegion(authAws, "us-west-2")
CkAuthAws::setCkServiceName(authAws, "appsync")
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest::ckSetAuthAws(rest,authAws)
; URL: https://appsync.us-west-2.amazonaws.com/
; Use the same region as specified above.
success = CkRest::ckConnect(rest,"appsync.us-west-2.amazonaws.com",443,1,1)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
ProcedureReturn
EndIf
CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
CkRest::ckAddHeader(rest,"X-Amz-Target","ListGraphqlApis")
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestNoBodySb(rest,"GET","/v1/apis",sbResponseBody)
If success <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
respStatusCode.i = CkRest::ckResponseStatusCode(rest)
Debug "response status code = " + Str(respStatusCode)
If respStatusCode <> 200
Debug "Response Header:"
Debug CkRest::ckResponseHeader(rest)
Debug "Response Body:"
Debug CkStringBuilder::ckGetAsString(sbResponseBody)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(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
apiId.s
arn.s
authenticationType.s
AuthorizerResultTtlInSeconds.i
AuthorizerUri.s
IdentityValidationExpression.s
CloudWatchLogsRoleArn.s
ExcludeVerboseContent.i
FieldLogLevel.s
name.s
AuthTTL.i
ClientId.s
IatTTL.i
Issuer.s
v_String.s
urisString.s
AppIdClientRegex.s
AwsRegion.s
DefaultAction.s
UserPoolId.s
wafWebAclArn.s
xrayEnabled.i
j.i
count_j.i
lambdaAuthorizerConfigAuthorizerResultTtlInSeconds.i
lambdaAuthorizerConfigAuthorizerUri.s
lambdaAuthorizerConfigIdentityValidationExpression.s
openIDConnectConfigAuthTTL.i
openIDConnectConfigClientId.s
openIDConnectConfigIatTTL.i
openIDConnectConfigIssuer.s
userPoolConfigAppIdClientRegex.s
userPoolConfigAwsRegion.s
userPoolConfigUserPoolId.s
nextToken.s = CkJsonObject::ckStringOf(jResp,"nextToken")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"graphqlApis")
While i < count_i
CkJsonObject::setCkI(jResp, i)
apiId = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].apiId")
arn = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].arn")
authenticationType = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].authenticationType")
AuthorizerResultTtlInSeconds = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds")
AuthorizerUri = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].lambdaAuthorizerConfig.authorizerUri")
IdentityValidationExpression = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].lambdaAuthorizerConfig.identityValidationExpression")
CloudWatchLogsRoleArn = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].logConfig.cloudWatchLogsRoleArn")
ExcludeVerboseContent = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].logConfig.excludeVerboseContent")
FieldLogLevel = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].logConfig.fieldLogLevel")
name = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].name")
AuthTTL = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].openIDConnectConfig.authTTL")
ClientId = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].openIDConnectConfig.clientId")
IatTTL = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].openIDConnectConfig.iatTTL")
Issuer = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].openIDConnectConfig.issuer")
v_String = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].tags.string")
urisString = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].uris.string")
AppIdClientRegex = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].userPoolConfig.appIdClientRegex")
AwsRegion = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].userPoolConfig.awsRegion")
DefaultAction = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].userPoolConfig.defaultAction")
UserPoolId = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].userPoolConfig.userPoolId")
wafWebAclArn = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].wafWebAclArn")
xrayEnabled = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].xrayEnabled")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"graphqlApis[i].additionalAuthenticationProviders")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
authenticationType = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].authenticationType")
lambdaAuthorizerConfigAuthorizerResultTtlInSeconds = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.authorizerResultTtlInSeconds")
lambdaAuthorizerConfigAuthorizerUri = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.authorizerUri")
lambdaAuthorizerConfigIdentityValidationExpression = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.identityValidationExpression")
openIDConnectConfigAuthTTL = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.authTTL")
openIDConnectConfigClientId = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.clientId")
openIDConnectConfigIatTTL = CkJsonObject::ckIntOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.iatTTL")
openIDConnectConfigIssuer = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.issuer")
userPoolConfigAppIdClientRegex = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.appIdClientRegex")
userPoolConfigAwsRegion = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.awsRegion")
userPoolConfigUserPoolId = CkJsonObject::ckStringOf(jResp,"graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.userPoolId")
j = j + 1
Wend
i = i + 1
Wend
; 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"
; }
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure