Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

Clickatell One API: Schedule a time-limited SMS reminder

See more Clickatell Examples

Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.

Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.

Clickatell API reference

Chilkat Objective-C Downloads

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

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

CkoDateTime *schedule = [[CkoDateTime alloc] init];
[schedule SetFromCurrentSystemTime];
[schedule AddSeconds: [NSNumber numberWithInt: 900]];
NSString *sendAt = [schedule GetAsTimestamp: NO];
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"messages[0].channel" value: @"sms"];
[body UpdateString: @"messages[0].to" value: @"PHONE_NUMBER"];
[body UpdateString: @"messages[0].content" value: @"Appointment reminder: please check in at reception."];
[body UpdateString: @"messages[0].scheduledDeliveryTime" value: sendAt];
[body UpdateInt: @"messages[0].validityPeriod" value: [NSNumber numberWithInt: 60]];
NSString *sender = @"";
if (sender != @"") {
    [body UpdateString: @"messages[0].from" value: sender];
}

NSLog(@"%@%@",@"Requested send time (UTC): ",sendAt);

CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
BOOL sent = [http HttpJson: @"POST" url: @"https://platform.clickatell.com/v1/message" json: body contentType: @"application/json" response: resp];
if ([resp.StatusCode intValue] == 0) {
    NSLog(@"%@",@"No HTTP response. Check the message report before resending.");
    return;
}

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

    return;
}

if ([reply HasMember: @"error.code"] == YES) {
    if ([reply IsNullOf: @"error.code"] != YES) {
        NSLog(@"%@%@%@%@",@"Submission error ",[reply StringOf: @"error.code"],@"  ",[reply StringOf: @"error.description"]);
        return;
    }

}

//  HTTP acceptance and the recipient result are separate checks.
if ((parsed != YES) || ([[reply JsonTypeOf: @"messages[0].accepted"] intValue] != 5)) {
    NSLog(@"%@",@"Missing recipient result. Check the message report.");
    return;
}

if ([reply BoolOf: @"messages[0].accepted"] != YES) {
    NSLog(@"%@%@%@%@",@"Message rejected: ",[reply StringOf: @"messages[0].error.code"],@"  ",[reply StringOf: @"messages[0].error.description"]);
    return;
}

if ([[reply JsonTypeOf: @"messages[0].apiMessageId"] intValue] != 1) {
    NSLog(@"%@",@"Accepted without a message ID. Check the message report.");
    return;
}

NSLog(@"%@%@",@"Accepted. Message ID: ",[reply StringOf: @"messages[0].apiMessageId"]);