(Tcl) qa.factura1.com.co Obtain Auth Token
Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.co
load ./chilkat.dll
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# Build the following JSON
# {
# "password": "MY_PASSWORD",
# "username": "MY_USERNAME"
# }
set json [new_CkJsonObject]
CkJsonObject_put_EmitCompact $json 0
CkJsonObject_UpdateString $json "password" "MY_PASSWORD"
CkJsonObject_UpdateString $json "username" "MY_USERNAME"
# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://qa.factura1.com.co/v2/auth" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkJsonObject $json
exit
}
set jsonResp [new_CkJsonObject]
CkJsonObject_put_EmitCompact $jsonResp 0
CkJsonObject_Load $jsonResp [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp
puts [CkJsonObject_emit $jsonResp]
puts "Access token: [CkJsonObject_stringOf $jsonResp token]"
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkJsonObject $jsonResp
|