Chilkat Online Tools

ListApps TCL Example

Amplify

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 "amplify"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://amplify.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "amplify.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" "ListApps"

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/apps" $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 "apps"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set appArn [CkJsonObject_stringOf $jResp "apps[i].appArn"]
    set appId [CkJsonObject_stringOf $jResp "apps[i].appId"]
    set BasicAuthCredentials [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationConfig.basicAuthCredentials"]
    set BuildSpec [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationConfig.buildSpec"]
    set EnableAutoBuild [CkJsonObject_IntOf $jResp "apps[i].autoBranchCreationConfig.enableAutoBuild"]
    set EnableBasicAuth [CkJsonObject_IntOf $jResp "apps[i].autoBranchCreationConfig.enableBasicAuth"]
    set EnablePerformanceMode [CkJsonObject_IntOf $jResp "apps[i].autoBranchCreationConfig.enablePerformanceMode"]
    set EnablePullRequestPreview [CkJsonObject_IntOf $jResp "apps[i].autoBranchCreationConfig.enablePullRequestPreview"]
    set v_String [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationConfig.environmentVariables.string"]
    set Framework [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationConfig.framework"]
    set PullRequestEnvironmentName [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationConfig.pullRequestEnvironmentName"]
    set Stage [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationConfig.stage"]
    set basicAuthCredentials [CkJsonObject_stringOf $jResp "apps[i].basicAuthCredentials"]
    set buildSpec [CkJsonObject_stringOf $jResp "apps[i].buildSpec"]
    set createTime [CkJsonObject_IntOf $jResp "apps[i].createTime"]
    set customHeaders [CkJsonObject_stringOf $jResp "apps[i].customHeaders"]
    set defaultDomain [CkJsonObject_stringOf $jResp "apps[i].defaultDomain"]
    set description [CkJsonObject_stringOf $jResp "apps[i].description"]
    set enableAutoBranchCreation [CkJsonObject_IntOf $jResp "apps[i].enableAutoBranchCreation"]
    set enableBasicAuth [CkJsonObject_IntOf $jResp "apps[i].enableBasicAuth"]
    set enableBranchAutoBuild [CkJsonObject_IntOf $jResp "apps[i].enableBranchAutoBuild"]
    set enableBranchAutoDeletion [CkJsonObject_IntOf $jResp "apps[i].enableBranchAutoDeletion"]
    set environmentVariablesString [CkJsonObject_stringOf $jResp "apps[i].environmentVariables.string"]
    set iamServiceRoleArn [CkJsonObject_stringOf $jResp "apps[i].iamServiceRoleArn"]
    set name [CkJsonObject_stringOf $jResp "apps[i].name"]
    set platform [CkJsonObject_stringOf $jResp "apps[i].platform"]
    set BranchName [CkJsonObject_stringOf $jResp "apps[i].productionBranch.branchName"]
    set LastDeployTime [CkJsonObject_IntOf $jResp "apps[i].productionBranch.lastDeployTime"]
    set Status [CkJsonObject_stringOf $jResp "apps[i].productionBranch.status"]
    set ThumbnailUrl [CkJsonObject_stringOf $jResp "apps[i].productionBranch.thumbnailUrl"]
    set repository [CkJsonObject_stringOf $jResp "apps[i].repository"]
    set repositoryCloneMethod [CkJsonObject_stringOf $jResp "apps[i].repositoryCloneMethod"]
    set tagsString [CkJsonObject_stringOf $jResp "apps[i].tags.string"]
    set updateTime [CkJsonObject_IntOf $jResp "apps[i].updateTime"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "apps[i].autoBranchCreationPatterns"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set strVal [CkJsonObject_stringOf $jResp "apps[i].autoBranchCreationPatterns[j]"]
        set j [expr $j + 1]
    }
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "apps[i].customRules"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set condition [CkJsonObject_stringOf $jResp "apps[i].customRules[j].condition"]
        set source [CkJsonObject_stringOf $jResp "apps[i].customRules[j].source"]
        set status [CkJsonObject_stringOf $jResp "apps[i].customRules[j].status"]
        set target [CkJsonObject_stringOf $jResp "apps[i].customRules[j].target"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

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

# {
#   "apps": [
#     {
#       "appArn": "string",
#       "appId": "string",
#       "autoBranchCreationConfig": {
#         "basicAuthCredentials": "string",
#         "buildSpec": "string",
#         "enableAutoBuild": boolean,
#         "enableBasicAuth": boolean,
#         "enablePerformanceMode": boolean,
#         "enablePullRequestPreview": boolean,
#         "environmentVariables": {
#           "string": "string"
#         },
#         "framework": "string",
#         "pullRequestEnvironmentName": "string",
#         "stage": "string"
#       },
#       "autoBranchCreationPatterns": [
#         "string"
#       ],
#       "basicAuthCredentials": "string",
#       "buildSpec": "string",
#       "createTime": number,
#       "customHeaders": "string",
#       "customRules": [
#         {
#           "condition": "string",
#           "source": "string",
#           "status": "string",
#           "target": "string"
#         }
#       ],
#       "defaultDomain": "string",
#       "description": "string",
#       "enableAutoBranchCreation": boolean,
#       "enableBasicAuth": boolean,
#       "enableBranchAutoBuild": boolean,
#       "enableBranchAutoDeletion": boolean,
#       "environmentVariables": {
#         "string": "string"
#       },
#       "iamServiceRoleArn": "string",
#       "name": "string",
#       "platform": "string",
#       "productionBranch": {
#         "branchName": "string",
#         "lastDeployTime": number,
#         "status": "string",
#         "thumbnailUrl": "string"
#       },
#       "repository": "string",
#       "repositoryCloneMethod": "string",
#       "tags": {
#         "string": "string"
#       },
#       "updateTime": number
#     }
#   ],
#   "nextToken": "string"
# }

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