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

Visual FoxPro
LOCAL loHttp
LOCAL loSchedule
LOCAL lcSendAt
LOCAL loBody
LOCAL lcSender
LOCAL loResp
LOCAL lnSent
LOCAL loReply
LOCAL lnParsed

*  Assumes Chilkat is unlocked. See Global Unlock Sample.
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
*  Load the key for this One API integration from your application configuration.
loHttp.SetRequestHeader("Authorization","ONE_API_KEY")
loHttp.SetRequestHeader("Accept","application/json")

loSchedule = CreateObject('Chilkat.CkDateTime')
loSchedule.SetFromCurrentSystemTime()
loSchedule.AddSeconds(900)
lcSendAt = loSchedule.GetAsTimestamp(0)
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("messages[0].channel","sms")
loBody.UpdateString("messages[0].to","PHONE_NUMBER")
loBody.UpdateString("messages[0].content","Appointment reminder: please check in at reception.")
loBody.UpdateString("messages[0].scheduledDeliveryTime",lcSendAt)
loBody.UpdateInt("messages[0].validityPeriod",60)
lcSender = ""
IF (lcSender <> "") THEN
    loBody.UpdateString("messages[0].from",lcSender)
ENDIF

? "Requested send time (UTC): " + lcSendAt

loResp = CreateObject('Chilkat.HttpResponse')
lnSent = loHttp.HttpJson("POST","https://platform.clickatell.com/v1/message",loBody,"application/json",loResp)
IF (loResp.StatusCode = 0) THEN
    ? "No HTTP response. Check the message report before resending."
    RELEASE loHttp
    RELEASE loSchedule
    RELEASE loBody
    RELEASE loResp
    CANCEL
ENDIF

loReply = CreateObject('Chilkat.JsonObject')
lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSent <> 1) OR (loResp.StatusCode <> 202)) THEN
    ? "Send returned HTTP " + STR(loResp.StatusCode)
    IF (loReply.HasMember("error.description") = 1) THEN
        ? loReply.StringOf("error.description")
    ENDIF

    RELEASE loHttp
    RELEASE loSchedule
    RELEASE loBody
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

IF (loReply.HasMember("error.code") = 1) THEN
    IF (loReply.IsNullOf("error.code") <> 1) THEN
        ? "Submission error " + loReply.StringOf("error.code") + "  " + loReply.StringOf("error.description")
        RELEASE loHttp
        RELEASE loSchedule
        RELEASE loBody
        RELEASE loResp
        RELEASE loReply
        CANCEL
    ENDIF

ENDIF

*  HTTP acceptance and the recipient result are separate checks.
IF ((lnParsed <> 1) OR (loReply.JsonTypeOf("messages[0].accepted") <> 5)) THEN
    ? "Missing recipient result. Check the message report."
    RELEASE loHttp
    RELEASE loSchedule
    RELEASE loBody
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

IF (loReply.BoolOf("messages[0].accepted") <> 1) THEN
    ? "Message rejected: " + loReply.StringOf("messages[0].error.code") + "  " + loReply.StringOf("messages[0].error.description")
    RELEASE loHttp
    RELEASE loSchedule
    RELEASE loBody
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

IF (loReply.JsonTypeOf("messages[0].apiMessageId") <> 1) THEN
    ? "Accepted without a message ID. Check the message report."
    RELEASE loHttp
    RELEASE loSchedule
    RELEASE loBody
    RELEASE loResp
    RELEASE loReply
    CANCEL
ENDIF

? "Accepted. Message ID: " + loReply.StringOf("messages[0].apiMessageId")

RELEASE loHttp
RELEASE loSchedule
RELEASE loBody
RELEASE loResp
RELEASE loReply