Sample code for 30+ languages & platforms
PureBasic 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 PureBasic Downloads

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Assumes Chilkat is unlocked. See Global Unlock Sample.
    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttp::setCkRequireSslCertVerify(http, 1)
    ;  Supply the key for this One API integration from application configuration.
    CkHttp::ckSetRequestHeader(http,"Authorization","ONE_API_KEY")
    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    ;  Use the provider-generated ID from an accepted One API send.
    CkHttp::ckSetUrlVar(http,"id","ONE_API_MESSAGE_ID")
    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpNoBody(http,"GET","https://platform.clickatell.com/v1/message/{$id}",resp)
    If CkHttpResponse::ckStatusCode(resp) = 0
        Debug "No HTTP response. Check the connection and retry the lookup."
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    reply.i = CkJsonObject::ckCreate()
    If reply.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    parsed.i = CkJsonObject::ckLoad(reply,CkHttpResponse::ckBodyStr(resp))
    If (success <> 1) OR ((CkHttpResponse::ckStatusCode(resp) <> 200))
        Debug "Clickatell returned HTTP " + Str(CkHttpResponse::ckStatusCode(resp))
        If parsed = 1
            If CkJsonObject::ckHasMember(reply,"error.description") = 1
                Debug CkJsonObject::ckStringOf(reply,"error.description")
            EndIf

        EndIf

        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        CkJsonObject::ckDispose(reply)
        ProcedureReturn
    EndIf

    If parsed <> 1
        Debug "Expected a JSON response."
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        CkJsonObject::ckDispose(reply)
        ProcedureReturn
    EndIf

    ;  A known SMS has a string status under the sms member.
    If CkJsonObject::ckJsonTypeOf(reply,"sms.status") <> 1
        If CkJsonObject::ckJsonTypeOf(reply,"whatsapp.status") = 1
            Debug "This message has WhatsApp status: " + CkJsonObject::ckStringOf(reply,"whatsapp.status")
        Else
            Debug "No SMS status was returned. Check the message ID and integration."
            If CkJsonObject::ckJsonTypeOf(reply,"status") = 1
                Debug "Reported status: " + CkJsonObject::ckStringOf(reply,"status")
            EndIf

        EndIf

        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        CkJsonObject::ckDispose(reply)
        ProcedureReturn
    EndIf

    Debug "SMS status: " + CkJsonObject::ckStringOf(reply,"sms.status")
    If CkJsonObject::ckJsonTypeOf(reply,"sms.timestamp") = 2
        ;  Read the provider timestamp as text to preserve every digit.
        Debug "Last status change (provider timestamp): " + CkJsonObject::ckStringOf(reply,"sms.timestamp")
    EndIf



    CkHttp::ckDispose(http)
    CkHttpResponse::ckDispose(resp)
    CkJsonObject::ckDispose(reply)


    ProcedureReturn
EndProcedure