Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

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.

Clickatell API reference

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oReply
LOCAL nParsed

nSuccess := 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
//  Supply the key for this One API integration from application configuration.
oHttp:SetRequestHeader("Authorization", "ONE_API_KEY")
oHttp:SetRequestHeader("Accept", "application/json")

//  Use the provider-generated ID from an accepted One API send.
oHttp:SetUrlVar("id", "ONE_API_MESSAGE_ID")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("GET", "https://platform.clickatell.com/v1/message/{$id}", oResp)
IF (oResp:StatusCode == 0)
    ? "No HTTP response. Check the connection and retry the lookup."
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

oReply := CreateObject("Chilkat.JsonObject")
nParsed := oReply:Load(oResp:BodyStr)
IF ((nSuccess != 1) .OR. ((oResp:StatusCode != 200)))
    ? "Clickatell returned HTTP " + Str(oResp:StatusCode)
    IF (nParsed == 1)
        IF (oReply:HasMember("error.description") == 1)
            ? oReply:StringOf("error.description")
        ENDIF

    ENDIF

    oHttp:destroy()
    oResp:destroy()
    oReply:destroy()
    RETURN
ENDIF

IF (nParsed != 1)
    ? "Expected a JSON response."
    oHttp:destroy()
    oResp:destroy()
    oReply:destroy()
    RETURN
ENDIF

//  A known SMS has a string status under the sms member.
IF (oReply:JsonTypeOf("sms.status") != 1)
    IF (oReply:JsonTypeOf("whatsapp.status") == 1)
        ? "This message has WhatsApp status: " + oReply:StringOf("whatsapp.status")
    ELSE
        ? "No SMS status was returned. Check the message ID and integration."
        IF (oReply:JsonTypeOf("status") == 1)
            ? "Reported status: " + oReply:StringOf("status")
        ENDIF

    ENDIF

    oHttp:destroy()
    oResp:destroy()
    oReply:destroy()
    RETURN
ENDIF

? "SMS status: " + oReply:StringOf("sms.status")
IF (oReply:JsonTypeOf("sms.timestamp") == 2)
    //  Read the provider timestamp as text to preserve every digit.
    ? "Last status change (provider timestamp): " + oReply:StringOf("sms.timestamp")
ENDIF

oHttp:destroy()
oResp:destroy()
oReply:destroy()