Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loReply
LOCAL lnParsed
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
* Supply the key for this One API integration from application configuration.
loHttp.SetRequestHeader("Authorization","ONE_API_KEY")
loHttp.SetRequestHeader("Accept","application/json")
* Use the provider-generated ID from an accepted One API send.
loHttp.SetUrlVar("id","ONE_API_MESSAGE_ID")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpNoBody("GET","https://platform.clickatell.com/v1/message/{$id}",loResp)
IF (loResp.StatusCode = 0) THEN
? "No HTTP response. Check the connection and retry the lookup."
RELEASE loHttp
RELEASE loResp
CANCEL
ENDIF
loReply = CreateObject('Chilkat.JsonObject')
lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSuccess <> 1) OR ((loResp.StatusCode <> 200))) THEN
? "Clickatell returned HTTP " + STR(loResp.StatusCode)
IF (lnParsed = 1) THEN
IF (loReply.HasMember("error.description") = 1) THEN
? loReply.StringOf("error.description")
ENDIF
ENDIF
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF (lnParsed <> 1) THEN
? "Expected a JSON response."
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
* A known SMS has a string status under the sms member.
IF (loReply.JsonTypeOf("sms.status") <> 1) THEN
IF (loReply.JsonTypeOf("whatsapp.status") = 1) THEN
? "This message has WhatsApp status: " + loReply.StringOf("whatsapp.status")
ELSE
? "No SMS status was returned. Check the message ID and integration."
IF (loReply.JsonTypeOf("status") = 1) THEN
? "Reported status: " + loReply.StringOf("status")
ENDIF
ENDIF
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
? "SMS status: " + loReply.StringOf("sms.status")
IF (loReply.JsonTypeOf("sms.timestamp") = 2) THEN
* Read the provider timestamp as text to preserve every digit.
? "Last status change (provider timestamp): " + loReply.StringOf("sms.timestamp")
ENDIF
RELEASE loHttp
RELEASE loResp
RELEASE loReply