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

Clickatell HTTP API: Send an SMS with query parameters

See more Clickatell Examples

Use an SMS integration configured for HTTP in the Clickatell Portal. The endpoint takes apiKey, to, and content as query parameters. Pass raw values to Chilkat so it can encode spaces, ampersands, and other reserved characters. Supply a country code and phone number as digits. Set from when your two-way integration requires a sender.

The URL contains the API key, recipient, and message text. Keep full request URLs out of logs and browser history. Check the per-message result after HTTP 202. If the connection is interrupted, check the Portal message report before resending. For the header-authenticated JSON workflow, see Send an SMS with One API.

Clickatell API reference

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkHttpRequestW.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);

    //  Use the key issued for this HTTP integration. Chilkat encodes each query value.
    CkHttpRequestW query;
    query.put_HttpVerb(L"GET");
    query.AddHeader(L"Accept",L"application/json");
    query.AddParam(L"apiKey",L"HTTP_API_KEY");
    query.AddParam(L"to",L"PHONE_NUMBER");
    query.AddParam(L"content",L"Test message: pickup between 2 & 4.");
    const wchar_t *sender = L"";
    if (sender != L"") {
        query.AddParam(L"from",sender);
    }

    CkHttpResponseW resp;
    success = http.HttpReq(L"https://platform.clickatell.com/messages/http/send",query,resp);
    if (resp.get_StatusCode() == 0) {
        wprintf(L"The send outcome is unknown. Check the message report before resending.\n");
        return;
    }

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

        }

        return;
    }

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

    //  A request-level error applies to the submission as a whole.
    if (reply.HasMember(L"errorCode") == true) {
        if (reply.IsNullOf(L"errorCode") != true) {
            wprintf(L"Submission error %s  %s\n",reply.stringOf(L"errorCode"),reply.stringOf(L"errorDescription"));
            return;
        }

    }

    int count = reply.SizeOfArray(L"messages");
    if (count <= 0) {
        wprintf(L"No recipient results returned. Check the message report before resending.\n");
        return;
    }

    int i = 0;
    while ((i < count)) {
        reply.put_I(i);
        int resultNumber = i + 1;
        //  JsonTypeOf returns 5 for a JSON boolean.
        if (reply.JsonTypeOf(L"messages[i].accepted") != 5) {
            wprintf(L"Result %d has no acceptance flag.\n",resultNumber);
        }
        else {
            if (reply.BoolOf(L"messages[i].accepted") == true) {
                const wchar_t *messageId = reply.stringOf(L"messages[i].apiMessageId");
                if ((reply.JsonTypeOf(L"messages[i].apiMessageId") != 1) || (messageId == L"")) {
                    wprintf(L"Result %d was accepted without a tracking ID.\n",resultNumber);
                }
                else {
                    wprintf(L"Result %d accepted. Message ID: %s\n",resultNumber,messageId);
                }

            }
            else {
                wprintf(L"Result %d rejected: %s  %s\n",resultNumber,reply.stringOf(L"messages[i].errorCode"),reply.stringOf(L"messages[i].errorDescription"));
            }

        }

        i = i + 1;
    }
    }