Chilkat Online Tools

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

# 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 "accessToken" "string"
CkJsonObject_UpdateString $json "autoBranchCreationConfig.basicAuthCredentials" "string"
CkJsonObject_UpdateString $json "autoBranchCreationConfig.buildSpec" "string"
CkJsonObject_UpdateInt $json "autoBranchCreationConfig.enableAutoBuild" 123
CkJsonObject_UpdateInt $json "autoBranchCreationConfig.enableBasicAuth" 123
CkJsonObject_UpdateInt $json "autoBranchCreationConfig.enablePerformanceMode" 123
CkJsonObject_UpdateInt $json "autoBranchCreationConfig.enablePullRequestPreview" 123
CkJsonObject_UpdateString $json "autoBranchCreationConfig.environmentVariables.string" "string"
CkJsonObject_UpdateString $json "autoBranchCreationConfig.framework" "string"
CkJsonObject_UpdateString $json "autoBranchCreationConfig.pullRequestEnvironmentName" "string"
CkJsonObject_UpdateString $json "autoBranchCreationConfig.stage" "string"
CkJsonObject_UpdateString $json "autoBranchCreationPatterns[0]" "string"
CkJsonObject_UpdateString $json "basicAuthCredentials" "string"
CkJsonObject_UpdateString $json "buildSpec" "string"
CkJsonObject_UpdateString $json "customHeaders" "string"
CkJsonObject_UpdateString $json "customRules[0].condition" "string"
CkJsonObject_UpdateString $json "customRules[0].source" "string"
CkJsonObject_UpdateString $json "customRules[0].status" "string"
CkJsonObject_UpdateString $json "customRules[0].target" "string"
CkJsonObject_UpdateString $json "description" "string"
CkJsonObject_UpdateInt $json "enableAutoBranchCreation" 123
CkJsonObject_UpdateInt $json "enableBasicAuth" 123
CkJsonObject_UpdateInt $json "enableBranchAutoBuild" 123
CkJsonObject_UpdateInt $json "enableBranchAutoDeletion" 123
CkJsonObject_UpdateString $json "environmentVariables.string" "string"
CkJsonObject_UpdateString $json "iamServiceRoleArn" "string"
CkJsonObject_UpdateString $json "name" "string"
CkJsonObject_UpdateString $json "oauthToken" "string"
CkJsonObject_UpdateString $json "platform" "string"
CkJsonObject_UpdateString $json "repository" "string"

# The JSON request body created by the above code:

# {
#   "accessToken": "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",
#   "customHeaders": "string",
#   "customRules": [
#     {
#       "condition": "string",
#       "source": "string",
#       "status": "string",
#       "target": "string"
#     }
#   ],
#   "description": "string",
#   "enableAutoBranchCreation": boolean,
#   "enableBasicAuth": boolean,
#   "enableBranchAutoBuild": boolean,
#   "enableBranchAutoDeletion": boolean,
#   "environmentVariables": {
#     "string": "string"
#   },
#   "iamServiceRoleArn": "string",
#   "name": "string",
#   "oauthToken": "string",
#   "platform": "string",
#   "repository": "string"
# }

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

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/apps/{appId}" $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 AppArn [CkJsonObject_stringOf $jResp "app.appArn"]
set AppId [CkJsonObject_stringOf $jResp "app.appId"]
set BasicAuthCredentials [CkJsonObject_stringOf $jResp "app.autoBranchCreationConfig.basicAuthCredentials"]
set BuildSpec [CkJsonObject_stringOf $jResp "app.autoBranchCreationConfig.buildSpec"]
set EnableAutoBuild [CkJsonObject_IntOf $jResp "app.autoBranchCreationConfig.enableAutoBuild"]
set EnableBasicAuth [CkJsonObject_IntOf $jResp "app.autoBranchCreationConfig.enableBasicAuth"]
set EnablePerformanceMode [CkJsonObject_IntOf $jResp "app.autoBranchCreationConfig.enablePerformanceMode"]
set EnablePullRequestPreview [CkJsonObject_IntOf $jResp "app.autoBranchCreationConfig.enablePullRequestPreview"]
set v_String [CkJsonObject_stringOf $jResp "app.autoBranchCreationConfig.environmentVariables.string"]
set Framework [CkJsonObject_stringOf $jResp "app.autoBranchCreationConfig.framework"]
set PullRequestEnvironmentName [CkJsonObject_stringOf $jResp "app.autoBranchCreationConfig.pullRequestEnvironmentName"]
set Stage [CkJsonObject_stringOf $jResp "app.autoBranchCreationConfig.stage"]
set appBasicAuthCredentials [CkJsonObject_stringOf $jResp "app.basicAuthCredentials"]
set appBuildSpec [CkJsonObject_stringOf $jResp "app.buildSpec"]
set CreateTime [CkJsonObject_IntOf $jResp "app.createTime"]
set CustomHeaders [CkJsonObject_stringOf $jResp "app.customHeaders"]
set DefaultDomain [CkJsonObject_stringOf $jResp "app.defaultDomain"]
set Description [CkJsonObject_stringOf $jResp "app.description"]
set EnableAutoBranchCreation [CkJsonObject_IntOf $jResp "app.enableAutoBranchCreation"]
set appEnableBasicAuth [CkJsonObject_IntOf $jResp "app.enableBasicAuth"]
set EnableBranchAutoBuild [CkJsonObject_IntOf $jResp "app.enableBranchAutoBuild"]
set EnableBranchAutoDeletion [CkJsonObject_IntOf $jResp "app.enableBranchAutoDeletion"]
set EnvironmentVariablesString [CkJsonObject_stringOf $jResp "app.environmentVariables.string"]
set IamServiceRoleArn [CkJsonObject_stringOf $jResp "app.iamServiceRoleArn"]
set Name [CkJsonObject_stringOf $jResp "app.name"]
set Platform [CkJsonObject_stringOf $jResp "app.platform"]
set BranchName [CkJsonObject_stringOf $jResp "app.productionBranch.branchName"]
set LastDeployTime [CkJsonObject_IntOf $jResp "app.productionBranch.lastDeployTime"]
set Status [CkJsonObject_stringOf $jResp "app.productionBranch.status"]
set ThumbnailUrl [CkJsonObject_stringOf $jResp "app.productionBranch.thumbnailUrl"]
set Repository [CkJsonObject_stringOf $jResp "app.repository"]
set RepositoryCloneMethod [CkJsonObject_stringOf $jResp "app.repositoryCloneMethod"]
set TagsString [CkJsonObject_stringOf $jResp "app.tags.string"]
set UpdateTime [CkJsonObject_IntOf $jResp "app.updateTime"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "app.autoBranchCreationPatterns"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "app.autoBranchCreationPatterns[i]"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "app.customRules"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set condition [CkJsonObject_stringOf $jResp "app.customRules[i].condition"]
    set source [CkJsonObject_stringOf $jResp "app.customRules[i].source"]
    set status [CkJsonObject_stringOf $jResp "app.customRules[i].status"]
    set target [CkJsonObject_stringOf $jResp "app.customRules[i].target"]
    set i [expr $i + 1]
}

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

# {
#   "app": {
#     "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
#   }
# }

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