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

Clickatell One API: Schedule a time-limited SMS reminder

See more Clickatell Examples

Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.

Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.

Clickatell API reference

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkDateTimeW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    HCkDateTimeW schedule;
    const wchar_t *sendAt;
    HCkJsonObjectW body;
    const wchar_t *sender;
    HCkHttpResponseW resp;
    BOOL sent;
    HCkJsonObjectW reply;
    BOOL parsed;

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

    schedule = CkDateTimeW_Create();
    CkDateTimeW_SetFromCurrentSystemTime(schedule);
    CkDateTimeW_AddSeconds(schedule,900);
    sendAt = CkDateTimeW_getAsTimestamp(schedule,FALSE);
    body = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(body,L"messages[0].channel",L"sms");
    CkJsonObjectW_UpdateString(body,L"messages[0].to",L"PHONE_NUMBER");
    CkJsonObjectW_UpdateString(body,L"messages[0].content",L"Appointment reminder: please check in at reception.");
    CkJsonObjectW_UpdateString(body,L"messages[0].scheduledDeliveryTime",sendAt);
    CkJsonObjectW_UpdateInt(body,L"messages[0].validityPeriod",60);
    sender = L"";
    if (sender != L"") {
        CkJsonObjectW_UpdateString(body,L"messages[0].from",sender);
    }

    wprintf(L"Requested send time (UTC): %s\n",sendAt);

    resp = CkHttpResponseW_Create();
    sent = CkHttpW_HttpJson(http,L"POST",L"https://platform.clickatell.com/v1/message",body,L"application/json",resp);
    if (CkHttpResponseW_getStatusCode(resp) == 0) {
        wprintf(L"No HTTP response. Check the message report before resending.\n");
        CkHttpW_Dispose(http);
        CkDateTimeW_Dispose(schedule);
        CkJsonObjectW_Dispose(body);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    reply = CkJsonObjectW_Create();
    parsed = CkJsonObjectW_Load(reply,CkHttpResponseW_bodyStr(resp));
    if ((sent != TRUE) || (CkHttpResponseW_getStatusCode(resp) != 202)) {
        wprintf(L"Send returned HTTP %d\n",CkHttpResponseW_getStatusCode(resp));
        if (CkJsonObjectW_HasMember(reply,L"error.description") == TRUE) {
            wprintf(L"%s\n",CkJsonObjectW_stringOf(reply,L"error.description"));
        }

        CkHttpW_Dispose(http);
        CkDateTimeW_Dispose(schedule);
        CkJsonObjectW_Dispose(body);
        CkHttpResponseW_Dispose(resp);
        CkJsonObjectW_Dispose(reply);
        return;
    }

    if (CkJsonObjectW_HasMember(reply,L"error.code") == TRUE) {
        if (CkJsonObjectW_IsNullOf(reply,L"error.code") != TRUE) {
            wprintf(L"Submission error %s  %s\n",CkJsonObjectW_stringOf(reply,L"error.code"),CkJsonObjectW_stringOf(reply,L"error.description"));
            CkHttpW_Dispose(http);
            CkDateTimeW_Dispose(schedule);
            CkJsonObjectW_Dispose(body);
            CkHttpResponseW_Dispose(resp);
            CkJsonObjectW_Dispose(reply);
            return;
        }

    }

    //  HTTP acceptance and the recipient result are separate checks.
    if ((parsed != TRUE) || (CkJsonObjectW_JsonTypeOf(reply,L"messages[0].accepted") != 5)) {
        wprintf(L"Missing recipient result. Check the message report.\n");
        CkHttpW_Dispose(http);
        CkDateTimeW_Dispose(schedule);
        CkJsonObjectW_Dispose(body);
        CkHttpResponseW_Dispose(resp);
        CkJsonObjectW_Dispose(reply);
        return;
    }

    if (CkJsonObjectW_BoolOf(reply,L"messages[0].accepted") != TRUE) {
        wprintf(L"Message rejected: %s  %s\n",CkJsonObjectW_stringOf(reply,L"messages[0].error.code"),CkJsonObjectW_stringOf(reply,L"messages[0].error.description"));
        CkHttpW_Dispose(http);
        CkDateTimeW_Dispose(schedule);
        CkJsonObjectW_Dispose(body);
        CkHttpResponseW_Dispose(resp);
        CkJsonObjectW_Dispose(reply);
        return;
    }

    if (CkJsonObjectW_JsonTypeOf(reply,L"messages[0].apiMessageId") != 1) {
        wprintf(L"Accepted without a message ID. Check the message report.\n");
        CkHttpW_Dispose(http);
        CkDateTimeW_Dispose(schedule);
        CkJsonObjectW_Dispose(body);
        CkHttpResponseW_Dispose(resp);
        CkJsonObjectW_Dispose(reply);
        return;
    }

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


    CkHttpW_Dispose(http);
    CkDateTimeW_Dispose(schedule);
    CkJsonObjectW_Dispose(body);
    CkHttpResponseW_Dispose(resp);
    CkJsonObjectW_Dispose(reply);

    }