Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oQuery
LOCAL cSender
LOCAL oResp
LOCAL oReply
LOCAL nParsed
LOCAL nCount
LOCAL i
LOCAL nResultNumber
LOCAL cMessageId
nSuccess := 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
// Use the key issued for this HTTP integration. Chilkat encodes each query value.
oQuery := CreateObject("Chilkat.HttpRequest")
oQuery:HttpVerb := "GET"
oQuery:AddHeader("Accept", "application/json")
oQuery:AddParam("apiKey", "HTTP_API_KEY")
oQuery:AddParam("to", "PHONE_NUMBER")
oQuery:AddParam("content", "Test message: pickup between 2 & 4.")
cSender := ""
IF (cSender != "")
oQuery:AddParam("from", cSender)
ENDIF
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpReq("https://platform.clickatell.com/messages/http/send", oQuery, oResp)
IF (oResp:StatusCode == 0)
? "The send outcome is unknown. Check the message report before resending."
oHttp:destroy()
oQuery:destroy()
oResp:destroy()
RETURN
ENDIF
oReply := CreateObject("Chilkat.JsonObject")
nParsed := oReply:Load(oResp:BodyStr)
IF ((nSuccess != 1) .OR. ((oResp:StatusCode != 202)))
? "Clickatell returned HTTP " + Str(oResp:StatusCode)
IF (nParsed == 1)
IF (oReply:HasMember("errorDescription") == 1)
? oReply:StringOf("errorDescription")
ENDIF
ENDIF
oHttp:destroy()
oQuery:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
IF (nParsed != 1)
? "Expected a JSON response."
oHttp:destroy()
oQuery:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
// A request-level error applies to the submission as a whole.
IF (oReply:HasMember("errorCode") == 1)
IF (oReply:IsNullOf("errorCode") != 1)
? "Submission error " + oReply:StringOf("errorCode") + " " + oReply:StringOf("errorDescription")
oHttp:destroy()
oQuery:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
ENDIF
nCount := oReply:SizeOfArray("messages")
IF (nCount <= 0)
? "No recipient results returned. Check the message report before resending."
oHttp:destroy()
oQuery:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
i := 0
DO WHILE (i < nCount)
oReply:I := i
nResultNumber := i + 1
// JsonTypeOf returns 5 for a JSON boolean.
IF (oReply:JsonTypeOf("messages[i].accepted") != 5)
? "Result " + Str(nResultNumber) + " has no acceptance flag."
ELSE
IF (oReply:BoolOf("messages[i].accepted") == 1)
cMessageId := oReply:StringOf("messages[i].apiMessageId")
IF ((oReply:JsonTypeOf("messages[i].apiMessageId") != 1) .OR. (cMessageId == ""))
? "Result " + Str(nResultNumber) + " was accepted without a tracking ID."
ELSE
? "Result " + Str(nResultNumber) + " accepted. Message ID: " + cMessageId
ENDIF
ELSE
? "Result " + Str(nResultNumber) + " rejected: " + oReply:StringOf("messages[i].errorCode") + " " + oReply:StringOf("messages[i].errorDescription")
ENDIF
ENDIF
i := i + 1
ENDDO
oHttp:destroy()
oQuery:destroy()
oResp:destroy()
oReply:destroy()