Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
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.
Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkDateTimeW.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");
CkDateTimeW schedule;
schedule.SetFromCurrentSystemTime();
schedule.AddSeconds(900);
const wchar_t *sendAt = schedule.getAsTimestamp(false);
CkJsonObjectW body;
body.UpdateString(L"messages[0].channel",L"sms");
body.UpdateString(L"messages[0].to",L"PHONE_NUMBER");
body.UpdateString(L"messages[0].content",L"Appointment reminder: please check in at reception.");
body.UpdateString(L"messages[0].scheduledDeliveryTime",sendAt);
body.UpdateInt(L"messages[0].validityPeriod",60);
const wchar_t *sender = L"";
if (sender != L"") {
body.UpdateString(L"messages[0].from",sender);
}
wprintf(L"Requested send time (UTC): %s\n",sendAt);
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"));
}