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

Unicode C++
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    CkHttpW http;
    http.put_RequireSslCertVerify(true);
    //  Supply the key for this One API integration from application configuration.
    http.SetRequestHeader(L"Authorization",L"ONE_API_KEY");
    http.SetRequestHeader(L"Accept",L"application/json");

    CkHttpResponseW resp;
    success = http.HttpNoBody(L"GET",L"https://platform.clickatell.com/v1/balance",resp);
    if (resp.get_StatusCode() == 0) {
        wprintf(L"No HTTP response. Check the connection and retry the lookup.\n");
        return;
    }

    CkJsonObjectW reply;
    bool parsed = reply.Load(resp.bodyStr());
    if ((success != true) || ((resp.get_StatusCode() != 200))) {
        wprintf(L"Clickatell returned HTTP %d\n",resp.get_StatusCode());
        if (parsed == true) {
            if (reply.HasMember(L"error.description") == true) {
                wprintf(L"%s\n",reply.stringOf(L"error.description"));
            }

        }

        return;
    }

    if (parsed != true) {
        wprintf(L"Expected a JSON response.\n");
        return;
    }

    //  JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
    if ((reply.JsonTypeOf(L"balance") != 2) || (reply.JsonTypeOf(L"currency") != 1)) {
        wprintf(L"The balance response is missing the amount or currency.\n");
        return;
    }

    wprintf(L"Account balance: %s %s\n",reply.stringOf(L"balance"),reply.stringOf(L"currency"));
    }