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

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

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

    //  Example approved wording: Order {{1}} is due for delivery on {{2}}.
    CkJsonObjectW body;
    body.UpdateString(L"messages[0].channel",L"whatsapp");
    body.UpdateString(L"messages[0].to",L"PHONE_NUMBER");
    body.UpdateString(L"messages[0].template.templateName",L"shipment_update");
    body.UpdateString(L"messages[0].template.language",L"en_US");
    body.UpdateString(L"messages[0].template.body.parameters.1",L"ORD-1042");
    body.UpdateString(L"messages[0].template.body.parameters.2",L"March 19");

    CkHttpResponseW resp;
    bool sent = http.HttpJson(L"POST",L"https://platform.clickatell.com/v1/message",body,L"application/json",resp);
    if (resp.get_StatusCode() == 0) {
        wprintf(L"No HTTP response. Check the message report before resending.\n");
        return;
    }

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

        return;
    }

    if (reply.HasMember(L"error.code") == true) {
        if (reply.IsNullOf(L"error.code") != true) {
            wprintf(L"Submission error %s  %s\n",reply.stringOf(L"error.code"),reply.stringOf(L"error.description"));
            return;
        }

    }

    //  HTTP acceptance and the recipient result are separate checks.
    if ((parsed != true) || (reply.JsonTypeOf(L"messages[0].accepted") != 5)) {
        wprintf(L"Missing recipient result. Check the message report.\n");
        return;
    }

    if (reply.BoolOf(L"messages[0].accepted") != true) {
        wprintf(L"Message rejected: %s  %s\n",reply.stringOf(L"messages[0].error.code"),reply.stringOf(L"messages[0].error.description"));
        return;
    }

    if (reply.JsonTypeOf(L"messages[0].apiMessageId") != 1) {
        wprintf(L"Accepted without a message ID. Check the message report.\n");
        return;
    }

    wprintf(L"Accepted. Message ID: %s\n",reply.stringOf(L"messages[0].apiMessageId"));
    }