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

Objective-C
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>

BOOL success = NO;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
//  Supply the key for this One API integration from application configuration.
[http SetRequestHeader: @"Authorization" value: @"ONE_API_KEY"];
[http SetRequestHeader: @"Accept" value: @"application/json"];

//  Use the provider-generated ID from an accepted One API send.
[http SetUrlVar: @"id" value: @"ONE_API_MESSAGE_ID"];
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpNoBody: @"GET" url: @"https://platform.clickatell.com/v1/message/{$id}" response: resp];
if ([resp.StatusCode intValue] == 0) {
    NSLog(@"%@",@"No HTTP response. Check the connection and retry the lookup.");
    return;
}

CkoJsonObject *reply = [[CkoJsonObject alloc] init];
BOOL parsed = [reply Load: resp.BodyStr];
if ((success != YES) || (([resp.StatusCode intValue] != 200))) {
    NSLog(@"%@%d",@"Clickatell returned HTTP ",[resp.StatusCode intValue]);
    if (parsed == YES) {
        if ([reply HasMember: @"error.description"] == YES) {
            NSLog(@"%@",[reply StringOf: @"error.description"]);
        }

    }

    return;
}

if (parsed != YES) {
    NSLog(@"%@",@"Expected a JSON response.");
    return;
}

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

    }

    return;
}

NSLog(@"%@%@",@"SMS status: ",[reply StringOf: @"sms.status"]);
if ([[reply JsonTypeOf: @"sms.timestamp"] intValue] == 2) {
    //  Read the provider timestamp as text to preserve every digit.
    NSLog(@"%@%@",@"Last status change (provider timestamp): ",[reply StringOf: @"sms.timestamp"]);
}