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

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.

Clickatell API reference

Chilkat AutoIt Downloads

AutoIt
;  Assumes Chilkat is unlocked. See Global Unlock Sample.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
;  Load the key for this One API integration from your application configuration.
$oHttp.SetRequestHeader "Authorization","ONE_API_KEY"
$oHttp.SetRequestHeader "Accept","application/json"

Local $sFirstPhone = "FIRST_PHONE_NUMBER"
Local $secondPhone = "SECOND_PHONE_NUMBER"
$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("messages[0].channel","sms")
$oBody.UpdateString("messages[0].to",$sFirstPhone)
$oBody.UpdateString("messages[0].content","Your appointment with Lee is at 10:00.")
$oBody.UpdateString("messages[0].clientMessageId","appt-1042")
$oBody.UpdateString("messages[1].channel","sms")
$oBody.UpdateString("messages[1].to",$secondPhone)
$oBody.UpdateString("messages[1].content","Your appointment with Sam is at 14:30.")
$oBody.UpdateString("messages[1].clientMessageId","appt-1043")

$oResp = ObjCreate("Chilkat.HttpResponse")
Local $bSent = $oHttp.HttpJson("POST","https://platform.clickatell.com/v1/message",$oBody,"application/json",$oResp)
If ($oResp.StatusCode = 0) Then
    ConsoleWrite("No HTTP response. Check the message report before resending." & @CRLF)
    Exit
EndIf

$oReply = ObjCreate("Chilkat.JsonObject")
Local $bParsed = $oReply.Load($oResp.BodyStr)
If (($bSent <> True) Or (($oResp.StatusCode <> 202) And ($oResp.StatusCode <> 207))) Then
    ConsoleWrite("Send returned HTTP " & $oResp.StatusCode & @CRLF)
    If ($oReply.HasMember("error.description") = True) Then
        ConsoleWrite($oReply.StringOf("error.description") & @CRLF)
    EndIf

    Exit
EndIf

If ($oReply.HasMember("error.code") = True) Then
    If ($oReply.IsNullOf("error.code") <> True) Then
        ConsoleWrite("Submission error " & $oReply.StringOf("error.code") & "  " & $oReply.StringOf("error.description") & @CRLF)
        Exit
    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.
$oResults = ObjCreate("Chilkat.JsonObject")
Local $i = 0
While ($i < 2)
    $oBody.I = $i
Local $sAppointment = $oBody.StringOf("messages[i].clientMessageId")
Local $sPhone = $oBody.StringOf("messages[i].to")
    $oResult = ObjCreate("Chilkat.JsonObject")
Local $bFound = $oReply.FindRecord2("messages","to",$sPhone,True,$oResult)
    $oResults.I = $i
    $oResults.UpdateString("appointments[i].clientMessageId",$sAppointment)
    If (($bFound <> True) Or ($oResult.JsonTypeOf("accepted") <> 5)) Then
        $oResults.UpdateString("appointments[i].outcome","unknown")
        ConsoleWrite($sAppointment & " has no confirmed result." & @CRLF)
    Else
        If ($oResult.BoolOf("accepted") = True) Then
            $oResults.UpdateString("appointments[i].outcome","accepted")
            If ($oResult.JsonTypeOf("apiMessageId") = 1) Then
                $oResults.UpdateString("appointments[i].apiMessageId",$oResult.StringOf("apiMessageId"))
            EndIf

            ConsoleWrite($sAppointment & " accepted." & @CRLF)
        Else
            $oResults.UpdateString("appointments[i].outcome","rejected")
            $oResults.UpdateString("appointments[i].reason",$oResult.StringOf("error.description"))
            ConsoleWrite($sAppointment & " rejected: " & $oResult.StringOf("error.description") & @CRLF)
        EndIf

    EndIf

    $i = $i + 1
Wend
;  This demo writes a snapshot. In an application, update the two appointment records.
Local $bSaved = $oResults.WriteFile("appointment-send-results.json")
If ($bSaved <> True) Then
    ConsoleWrite("Could not save the results. Reconcile the submitted messages before retrying." & @CRLF)
    Exit
EndIf

ConsoleWrite("Saved appointment-send-results.json" & @CRLF)