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

Delphi DLL
var
success: Boolean;
http: HCkHttp;
resp: HCkHttpResponse;
reply: HCkJsonObject;
parsed: Boolean;

begin
success := False;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);
//  Supply the key for this One API integration from application configuration.
CkHttp_SetRequestHeader(http,'Authorization','ONE_API_KEY');
CkHttp_SetRequestHeader(http,'Accept','application/json');

//  Use the provider-generated ID from an accepted One API send.
CkHttp_SetUrlVar(http,'id','ONE_API_MESSAGE_ID');
resp := CkHttpResponse_Create();
success := CkHttp_HttpNoBody(http,'GET','https://platform.clickatell.com/v1/message/{$id}',resp);
if (CkHttpResponse_getStatusCode(resp) = 0) then
  begin
    Memo1.Lines.Add('No HTTP response. Check the connection and retry the lookup.');
    Exit;
  end;
reply := CkJsonObject_Create();
parsed := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
if ((success <> True) or ((CkHttpResponse_getStatusCode(resp) <> 200))) then
  begin
    Memo1.Lines.Add('Clickatell returned HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    if (parsed = True) then
      begin
        if (CkJsonObject_HasMember(reply,'error.description') = True) then
          begin
            Memo1.Lines.Add(CkJsonObject__stringOf(reply,'error.description'));
          end;
      end;
    Exit;
  end;
if (parsed <> True) then
  begin
    Memo1.Lines.Add('Expected a JSON response.');
    Exit;
  end;

//  A known SMS has a string status under the sms member.
if (CkJsonObject_JsonTypeOf(reply,'sms.status') <> 1) then
  begin
    if (CkJsonObject_JsonTypeOf(reply,'whatsapp.status') = 1) then
      begin
        Memo1.Lines.Add('This message has WhatsApp status: ' + CkJsonObject__stringOf(reply,'whatsapp.status'));
      end
    else
      begin
        Memo1.Lines.Add('No SMS status was returned. Check the message ID and integration.');
        if (CkJsonObject_JsonTypeOf(reply,'status') = 1) then
          begin
            Memo1.Lines.Add('Reported status: ' + CkJsonObject__stringOf(reply,'status'));
          end;
      end;
    Exit;
  end;
Memo1.Lines.Add('SMS status: ' + CkJsonObject__stringOf(reply,'sms.status'));
if (CkJsonObject_JsonTypeOf(reply,'sms.timestamp') = 2) then
  begin
    //  Read the provider timestamp as text to preserve every digit.
    Memo1.Lines.Add('Last status change (provider timestamp): ' + CkJsonObject__stringOf(reply,'sms.timestamp'));
  end;

CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(reply);