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

Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
var http = new CkHttp();
http.RequireSslCertVerify = true;
//  Supply the key for this One API integration from application configuration.
http.SetRequestHeader("Authorization","ONE_API_KEY");
http.SetRequestHeader("Accept","application/json");

//  Use the provider-generated ID from an accepted One API send.
http.SetUrlVar("id","ONE_API_MESSAGE_ID");
var resp = new CkHttpResponse();
success = http.HttpNoBody("GET","https://platform.clickatell.com/v1/message/{$id}",resp);
if (resp.StatusCode == 0) {
    console.log("No HTTP response. Check the connection and retry the lookup.");
    return;
}

var reply = new CkJsonObject();
var parsed = reply.Load(resp.BodyStr);
if ((success !== true) || ((resp.StatusCode !== 200))) {
    console.log("Clickatell returned HTTP " + resp.StatusCode);
    if (parsed == true) {
        if (reply.HasMember("error.description") == true) {
            console.log(reply.StringOf("error.description"));
        }

    }

    return;
}

if (parsed !== true) {
    console.log("Expected a JSON response.");
    return;
}

//  A known SMS has a string status under the sms member.
if (reply.JsonTypeOf("sms.status") !== 1) {
    if (reply.JsonTypeOf("whatsapp.status") == 1) {
        console.log("This message has WhatsApp status: " + reply.StringOf("whatsapp.status"));
    }
    else {
        console.log("No SMS status was returned. Check the message ID and integration.");
        if (reply.JsonTypeOf("status") == 1) {
            console.log("Reported status: " + reply.StringOf("status"));
        }

    }

    return;
}

console.log("SMS status: " + reply.StringOf("sms.status"));
if (reply.JsonTypeOf("sms.timestamp") == 2) {
    //  Read the provider timestamp as text to preserve every digit.
    console.log("Last status change (provider timestamp): " + reply.StringOf("sms.timestamp"));
}