Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
Clickatell One API: Send personalized SMS reminders in a batch
See more Clickatell Examples
Send two appointments in one request with a different text and application ID for each. Use two distinct recipient numbers in international digits. For a US two-way integration, add its provisioned from number to each message.
Read each recipient result even when HTTP 207 reports a mixed outcome. Save the accepted provider ID against the appointment. A missing result calls for checking the message report before retrying. A client message ID helps correlate records and does not guarantee deduplication.
Chilkat Visual FoxPro Downloads
LOCAL loHttp
LOCAL lcFirstPhone
LOCAL lcSecondPhone
LOCAL loBody
LOCAL loResp
LOCAL lnSent
LOCAL loReply
LOCAL lnParsed
LOCAL loResults
LOCAL i
LOCAL lcAppointment
LOCAL lcPhone
LOCAL loResult
LOCAL lnFound
LOCAL lnSaved
* 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")
lcFirstPhone = "FIRST_PHONE_NUMBER"
lcSecondPhone = "SECOND_PHONE_NUMBER"
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("messages[0].channel","sms")
loBody.UpdateString("messages[0].to",lcFirstPhone)
loBody.UpdateString("messages[0].content","Your appointment with Lee is at 10:00.")
loBody.UpdateString("messages[0].clientMessageId","appt-1042")
loBody.UpdateString("messages[1].channel","sms")
loBody.UpdateString("messages[1].to",lcSecondPhone)
loBody.UpdateString("messages[1].content","Your appointment with Sam is at 14:30.")
loBody.UpdateString("messages[1].clientMessageId","appt-1043")
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 loBody
RELEASE loResp
CANCEL
ENDIF
loReply = CreateObject('Chilkat.JsonObject')
lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSent <> 1) OR ((loResp.StatusCode <> 202) AND (loResp.StatusCode <> 207))) THEN
? "Send returned HTTP " + STR(loResp.StatusCode)
IF (loReply.HasMember("error.description") = 1) THEN
? loReply.StringOf("error.description")
ENDIF
RELEASE loHttp
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 loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
ENDIF
* Look up each submitted appointment in the reply using its unique recipient.
* This works even if the result order changes or clientMessageId is absent.
loResults = CreateObject('Chilkat.JsonObject')
i = 0
DO WHILE (i < 2)
loBody.I = i
lcAppointment = loBody.StringOf("messages[i].clientMessageId")
lcPhone = loBody.StringOf("messages[i].to")
loResult = CreateObject('Chilkat.JsonObject')
lnFound = loReply.FindRecord2("messages","to",lcPhone,1,loResult)
loResults.I = i
loResults.UpdateString("appointments[i].clientMessageId",lcAppointment)
IF ((lnFound <> 1) OR (loResult.JsonTypeOf("accepted") <> 5)) THEN
loResults.UpdateString("appointments[i].outcome","unknown")
? lcAppointment + " has no confirmed result."
ELSE
IF (loResult.BoolOf("accepted") = 1) THEN
loResults.UpdateString("appointments[i].outcome","accepted")
IF (loResult.JsonTypeOf("apiMessageId") = 1) THEN
loResults.UpdateString("appointments[i].apiMessageId",loResult.StringOf("apiMessageId"))
ENDIF
? lcAppointment + " accepted."
ELSE
loResults.UpdateString("appointments[i].outcome","rejected")
loResults.UpdateString("appointments[i].reason",loResult.StringOf("error.description"))
? lcAppointment + " rejected: " + loResult.StringOf("error.description")
ENDIF
ENDIF
i = i + 1
ENDDO
* This demo writes a snapshot. In an application, update the two appointment records.
lnSaved = loResults.WriteFile("appointment-send-results.json")
IF (lnSaved <> 1) THEN
? "Could not save the results. Reconcile the submitted messages before retrying."
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
RELEASE loResults
RELEASE loResult
CANCEL
ENDIF
? "Saved appointment-send-results.json"
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
RELEASE loResults
RELEASE loResult