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

Clickatell One API: Send an approved WhatsApp shipment template

See more Clickatell Examples

Send a business-initiated shipment update, including outside an open customer service window. First approve a template on the WhatsApp integration with two positional body placeholders for the order number and delivery date. Supply its exact name and approved language. The keys 1 and 2 refer to those placeholders in order.

Clickatell API reference

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.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"];

//  Example approved wording: Order {{1}} is due for delivery on {{2}}.
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"messages[0].channel" value: @"whatsapp"];
[body UpdateString: @"messages[0].to" value: @"PHONE_NUMBER"];
[body UpdateString: @"messages[0].template.templateName" value: @"shipment_update"];
[body UpdateString: @"messages[0].template.language" value: @"en_US"];
[body UpdateString: @"messages[0].template.body.parameters.1" value: @"ORD-1042"];
[body UpdateString: @"messages[0].template.body.parameters.2" value: @"March 19"];

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"]);