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