Tcl
Tcl
WhatsApp - Get a User's Account Information
Demonstrates how to retrieve a user account by sending a GET request on the users endpoint.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# Implements the following CURL command:
# curl -X GET https://example.com/v1/users/username \
# -H "Authorization: Bearer your-auth-token"
# Adds the "Authorization: Bearer your-auth-token" header.
CkHttp_put_AuthToken $http "your-auth-token"
set sbResponseBody [new_CkStringBuilder]
set success [CkHttp_QuickGetSb $http "https://example.com/v1/users/username" $sbResponseBody]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
exit
}
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0
puts "Response Body:"
puts [CkJsonObject_emit $jResp]
set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
puts "Response Header:"
puts [CkHttp_lastHeader $http]
puts "Failed."
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
exit
}
# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)
# {
# "users": [
# {
# "ROLES": "ROLE_ADMIN | ROLE_USER",
# "username": "username"
# }
# ]
# }
# Sample code for parsing the JSON response...
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "users"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set ROLES [CkJsonObject_stringOf $jResp "users[i].ROLES"]
set username [CkJsonObject_stringOf $jResp "users[i].username"]
set i [expr $i + 1]
}
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp