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

Clickatell One API: Read the account balance and currency

See more Clickatell Examples

Request the messaging balance associated with a One API integration key. The response supplies both the decimal amount and its currency. Read the amount as text for display to preserve its precision. A zero balance is a valid result. For example, a billing dashboard can display 1267.92865 ZAR.

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

CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpNoBody: @"GET" url: @"https://platform.clickatell.com/v1/balance" 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;
}

//  JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
if (([[reply JsonTypeOf: @"balance"] intValue] != 2) || ([[reply JsonTypeOf: @"currency"] intValue] != 1)) {
    NSLog(@"%@",@"The balance response is missing the amount or currency.");
    return;
}

NSLog(@"%@%@%@%@",@"Account balance: ",[reply StringOf: @"balance"],@" ",[reply StringOf: @"currency"]);