Tcl Requires Chilkat v11.0.0+
Tcl
Clickatell One API: Look up SMS delivery status
See more Clickatell Examples
Use the apiMessageId returned by the One API send example and the same integration key. The ID goes in the URL path. The SMS result contains sms.status and the timestamp of the last status change. For example, QUEUED means processing is pending and DEVICE_ACK indicates a device acknowledgment.
The response can also contain a WhatsApp result or have no identifiable channel for an unknown message. For ongoing delivery updates, configure delivery notifications in the integration. This example performs one lookup.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Assumes Chilkat is unlocked. See Global Unlock Sample.
set http [new_CkHttp]
CkHttp_put_RequireSslCertVerify $http 1
# Supply the key for this One API integration from application configuration.
CkHttp_SetRequestHeader $http "Authorization" "ONE_API_KEY"
CkHttp_SetRequestHeader $http "Accept" "application/json"
# Use the provider-generated ID from an accepted One API send.
CkHttp_SetUrlVar $http "id" "ONE_API_MESSAGE_ID"
set resp [new_CkHttpResponse]
set success [CkHttp_HttpNoBody $http "GET" "https://platform.clickatell.com/v1/message/{$id}" $resp]
if {[CkHttpResponse_get_StatusCode $resp] == 0} then {
puts "No HTTP response. Check the connection and retry the lookup."
delete_CkHttp $http
delete_CkHttpResponse $resp
exit
}
set reply [new_CkJsonObject]
set parsed [CkJsonObject_Load $reply [CkHttpResponse_bodyStr $resp]]
if {expr [$success != 1] || [[CkHttpResponse_get_StatusCode $resp] != 200]} then {
puts "Clickatell returned HTTP [CkHttpResponse_get_StatusCode $resp]"
if {$parsed == 1} then {
if {[CkJsonObject_HasMember $reply "error.description"] == 1} then {
puts [CkJsonObject_stringOf $reply error.description]
}
}
delete_CkHttp $http
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
if {$parsed != 1} then {
puts "Expected a JSON response."
delete_CkHttp $http
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
# A known SMS has a string status under the sms member.
if {[CkJsonObject_JsonTypeOf $reply "sms.status"] != 1} then {
if {[CkJsonObject_JsonTypeOf $reply "whatsapp.status"] == 1} then {
puts "This message has WhatsApp status: [CkJsonObject_stringOf $reply whatsapp.status]"
} else {
puts "No SMS status was returned. Check the message ID and integration."
if {[CkJsonObject_JsonTypeOf $reply "status"] == 1} then {
puts "Reported status: [CkJsonObject_stringOf $reply status]"
}
}
delete_CkHttp $http
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
puts "SMS status: [CkJsonObject_stringOf $reply sms.status]"
if {[CkJsonObject_JsonTypeOf $reply "sms.timestamp"] == 2} then {
# Read the provider timestamp as text to preserve every digit.
puts "Last status change (provider timestamp): [CkJsonObject_stringOf $reply sms.timestamp]"
}
delete_CkHttp $http
delete_CkHttpResponse $resp
delete_CkJsonObject $reply