Sample code for 30+ languages & platforms
Tcl

qa.factura1.com.co Obtain Auth Token

See more HTTP Misc Examples

Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.co

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# 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"

set resp [new_CkHttpResponse]

set success [CkHttp_HttpJson $http "POST" "https://qa.factura1.com.co/v2/auth" $json "application/json" $resp]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkHttpResponse $resp
    exit
}

set jsonResp [new_CkJsonObject]

CkJsonObject_put_EmitCompact $jsonResp 0
CkJsonObject_Load $jsonResp [CkHttpResponse_bodyStr $resp]

puts [CkJsonObject_emit $jsonResp]

puts "Access token: [CkJsonObject_stringOf $jsonResp token]"

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkJsonObject $jsonResp