Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL oHttp
LOCAL oSchedule
LOCAL cSendAt
LOCAL oBody
LOCAL cSender
LOCAL oResp
LOCAL nSent
LOCAL oReply
LOCAL nParsed
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
// Load the key for this One API integration from your application configuration.
oHttp:SetRequestHeader("Authorization", "ONE_API_KEY")
oHttp:SetRequestHeader("Accept", "application/json")
oSchedule := CreateObject("Chilkat.CkDateTime")
oSchedule:SetFromCurrentSystemTime()
oSchedule:AddSeconds(900)
cSendAt := oSchedule:GetAsTimestamp(0)
oBody := CreateObject("Chilkat.JsonObject")
oBody:UpdateString("messages[0].channel", "sms")
oBody:UpdateString("messages[0].to", "PHONE_NUMBER")
oBody:UpdateString("messages[0].content", "Appointment reminder: please check in at reception.")
oBody:UpdateString("messages[0].scheduledDeliveryTime", cSendAt)
oBody:UpdateInt("messages[0].validityPeriod", 60)
cSender := ""
IF (cSender != "")
oBody:UpdateString("messages[0].from", cSender)
ENDIF
? "Requested send time (UTC): " + cSendAt
oResp := CreateObject("Chilkat.HttpResponse")
nSent := oHttp:HttpJson("POST", "https://platform.clickatell.com/v1/message", oBody, "application/json", oResp)
IF (oResp:StatusCode == 0)
? "No HTTP response. Check the message report before resending."
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
RETURN
ENDIF
oReply := CreateObject("Chilkat.JsonObject")
nParsed := oReply:Load(oResp:BodyStr)
IF ((nSent != 1) .OR. (oResp:StatusCode != 202))
? "Send returned HTTP " + Str(oResp:StatusCode)
IF (oReply:HasMember("error.description") == 1)
? oReply:StringOf("error.description")
ENDIF
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
IF (oReply:HasMember("error.code") == 1)
IF (oReply:IsNullOf("error.code") != 1)
? "Submission error " + oReply:StringOf("error.code") + " " + oReply:StringOf("error.description")
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
ENDIF
// HTTP acceptance and the recipient result are separate checks.
IF ((nParsed != 1) .OR. (oReply:JsonTypeOf("messages[0].accepted") != 5))
? "Missing recipient result. Check the message report."
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
IF (oReply:BoolOf("messages[0].accepted") != 1)
? "Message rejected: " + oReply:StringOf("messages[0].error.code") + " " + oReply:StringOf("messages[0].error.description")
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
IF (oReply:JsonTypeOf("messages[0].apiMessageId") != 1)
? "Accepted without a message ID. Check the message report."
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
oReply:destroy()
RETURN
ENDIF
? "Accepted. Message ID: " + oReply:StringOf("messages[0].apiMessageId")
oHttp:destroy()
oSchedule:destroy()
oBody:destroy()
oResp:destroy()
oReply:destroy()