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

CkPhp
<?php

include("chilkat.php");

$success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
$http = new CkHttp();
$http->put_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');
$resp = new CkHttpResponse();
$success = $http->HttpNoBody('GET','https://platform.clickatell.com/v1/message/{$id}',$resp);
if ($resp->get_StatusCode() == 0) {
    print 'No HTTP response. Check the connection and retry the lookup.' . "\n";
    exit;
}

$reply = new CkJsonObject();
$parsed = $reply->Load($resp->bodyStr());
if (($success != true) or (($resp->get_StatusCode() != 200))) {
    print 'Clickatell returned HTTP ' . $resp->get_StatusCode() . "\n";
    if ($parsed == true) {
        if ($reply->HasMember('error.description') == true) {
            print $reply->stringOf('error.description') . "\n";
        }

    }

    exit;
}

if ($parsed != true) {
    print 'Expected a JSON response.' . "\n";
    exit;
}

//  A known SMS has a string status under the sms member.
if ($reply->JsonTypeOf('sms.status') != 1) {
    if ($reply->JsonTypeOf('whatsapp.status') == 1) {
        print 'This message has WhatsApp status: ' . $reply->stringOf('whatsapp.status') . "\n";
    }
    else {
        print 'No SMS status was returned. Check the message ID and integration.' . "\n";
        if ($reply->JsonTypeOf('status') == 1) {
            print 'Reported status: ' . $reply->stringOf('status') . "\n";
        }

    }

    exit;
}

print 'SMS status: ' . $reply->stringOf('sms.status') . "\n";
if ($reply->JsonTypeOf('sms.timestamp') == 2) {
    //  Read the provider timestamp as text to preserve every digit.
    print 'Last status change (provider timestamp): ' . $reply->stringOf('sms.timestamp') . "\n";
}


?>