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

C
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    HCkJsonObject body;
    HCkHttpResponse resp;
    BOOL sent;
    HCkJsonObject reply;
    BOOL parsed;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    http = CkHttp_Create();
    CkHttp_putRequireSslCertVerify(http,TRUE);
    //  Load the key for this One API integration from your application configuration.
    CkHttp_SetRequestHeader(http,"Authorization","ONE_API_KEY");
    CkHttp_SetRequestHeader(http,"Accept","application/json");

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

    resp = CkHttpResponse_Create();
    sent = CkHttp_HttpJson(http,"POST","https://platform.clickatell.com/v1/message",body,"application/json",resp);
    if (CkHttpResponse_getStatusCode(resp) == 0) {
        printf("No HTTP response. Check the message report before resending.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(body);
        CkHttpResponse_Dispose(resp);
        return;
    }

    reply = CkJsonObject_Create();
    parsed = CkJsonObject_Load(reply,CkHttpResponse_bodyStr(resp));
    if ((sent != TRUE) || (CkHttpResponse_getStatusCode(resp) != 202)) {
        printf("Send returned HTTP %d\n",CkHttpResponse_getStatusCode(resp));
        if (CkJsonObject_HasMember(reply,"error.description") == TRUE) {
            printf("%s\n",CkJsonObject_stringOf(reply,"error.description"));
        }

        CkHttp_Dispose(http);
        CkJsonObject_Dispose(body);
        CkHttpResponse_Dispose(resp);
        CkJsonObject_Dispose(reply);
        return;
    }

    if (CkJsonObject_HasMember(reply,"error.code") == TRUE) {
        if (CkJsonObject_IsNullOf(reply,"error.code") != TRUE) {
            printf("Submission error %s  %s\n",CkJsonObject_stringOf(reply,"error.code"),CkJsonObject_stringOf(reply,"error.description"));
            CkHttp_Dispose(http);
            CkJsonObject_Dispose(body);
            CkHttpResponse_Dispose(resp);
            CkJsonObject_Dispose(reply);
            return;
        }

    }

    //  HTTP acceptance and the recipient result are separate checks.
    if ((parsed != TRUE) || (CkJsonObject_JsonTypeOf(reply,"messages[0].accepted") != 5)) {
        printf("Missing recipient result. Check the message report.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(body);
        CkHttpResponse_Dispose(resp);
        CkJsonObject_Dispose(reply);
        return;
    }

    if (CkJsonObject_BoolOf(reply,"messages[0].accepted") != TRUE) {
        printf("Message rejected: %s  %s\n",CkJsonObject_stringOf(reply,"messages[0].error.code"),CkJsonObject_stringOf(reply,"messages[0].error.description"));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(body);
        CkHttpResponse_Dispose(resp);
        CkJsonObject_Dispose(reply);
        return;
    }

    if (CkJsonObject_JsonTypeOf(reply,"messages[0].apiMessageId") != 1) {
        printf("Accepted without a message ID. Check the message report.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(body);
        CkHttpResponse_Dispose(resp);
        CkJsonObject_Dispose(reply);
        return;
    }

    printf("Accepted. Message ID: %s\n",CkJsonObject_stringOf(reply,"messages[0].apiMessageId"));


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(body);
    CkHttpResponse_Dispose(resp);
    CkJsonObject_Dispose(reply);

    }