Tcl Requires Chilkat v11.0.0+
Tcl
Clickatell HTTP API: Send an SMS with query parameters
See more Clickatell Examples
Use an SMS integration configured for HTTP in the Clickatell Portal. The endpoint takes apiKey, to, and content as query parameters. Pass raw values to Chilkat so it can encode spaces, ampersands, and other reserved characters. Supply a country code and phone number as digits. Set from when your two-way integration requires a sender.
The URL contains the API key, recipient, and message text. Keep full request URLs out of logs and browser history. Check the per-message result after HTTP 202. If the connection is interrupted, check the Portal message report before resending. For the header-authenticated JSON workflow, see Send an SMS with One API.
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
# Use the key issued for this HTTP integration. Chilkat encodes each query value.
set query [new_CkHttpRequest]
CkHttpRequest_put_HttpVerb $query "GET"
CkHttpRequest_AddHeader $query "Accept" "application/json"
CkHttpRequest_AddParam $query "apiKey" "HTTP_API_KEY"
CkHttpRequest_AddParam $query "to" "PHONE_NUMBER"
CkHttpRequest_AddParam $query "content" "Test message: pickup between 2 & 4."
set sender ""
if {$sender != ""} then {
CkHttpRequest_AddParam $query "from" $sender
}
set resp [new_CkHttpResponse]
set success [CkHttp_HttpReq $http "https://platform.clickatell.com/messages/http/send" $query $resp]
if {[CkHttpResponse_get_StatusCode $resp] == 0} then {
puts "The send outcome is unknown. Check the message report before resending."
delete_CkHttp $http
delete_CkHttpRequest $query
delete_CkHttpResponse $resp
exit
}
set reply [new_CkJsonObject]
set parsed [CkJsonObject_Load $reply [CkHttpResponse_bodyStr $resp]]
if {expr [$success != 1] || [[CkHttpResponse_get_StatusCode $resp] != 202]} then {
puts "Clickatell returned HTTP [CkHttpResponse_get_StatusCode $resp]"
if {$parsed == 1} then {
if {[CkJsonObject_HasMember $reply "errorDescription"] == 1} then {
puts [CkJsonObject_stringOf $reply errorDescription]
}
}
delete_CkHttp $http
delete_CkHttpRequest $query
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
if {$parsed != 1} then {
puts "Expected a JSON response."
delete_CkHttp $http
delete_CkHttpRequest $query
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
# A request-level error applies to the submission as a whole.
if {[CkJsonObject_HasMember $reply "errorCode"] == 1} then {
if {[CkJsonObject_IsNullOf $reply "errorCode"] != 1} then {
puts "Submission error [CkJsonObject_stringOf $reply errorCode] [CkJsonObject_stringOf $reply errorDescription]"
delete_CkHttp $http
delete_CkHttpRequest $query
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
}
set count [CkJsonObject_SizeOfArray $reply "messages"]
if {$count <= 0} then {
puts "No recipient results returned. Check the message report before resending."
delete_CkHttp $http
delete_CkHttpRequest $query
delete_CkHttpResponse $resp
delete_CkJsonObject $reply
exit
}
set i 0
while {$i < $count} {
CkJsonObject_put_I $reply $i
set resultNumber [expr $i + 1]
# JsonTypeOf returns 5 for a JSON boolean.
if {[CkJsonObject_JsonTypeOf $reply "messages[i].accepted"] != 5} then {
puts "Result $resultNumber has no acceptance flag."
} else {
if {[CkJsonObject_BoolOf $reply "messages[i].accepted"] == 1} then {
set messageId [CkJsonObject_stringOf $reply "messages[i].apiMessageId"]
if {expr [[CkJsonObject_JsonTypeOf $reply "messages[i].apiMessageId"] != 1] || [$messageId == ""]} then {
puts "Result $resultNumber was accepted without a tracking ID."
} else {
puts "Result $resultNumber accepted. Message ID: $messageId"
}
} else {
puts "Result $resultNumber rejected: [CkJsonObject_stringOf $reply {messages[i].errorCode}] [CkJsonObject_stringOf $reply {messages[i].errorDescription}]"
}
}
set i [expr $i + 1]
}
delete_CkHttp $http
delete_CkHttpRequest $query
delete_CkHttpResponse $resp
delete_CkJsonObject $reply