VB.NET Requires Chilkat v11.0.0+
VB.NET
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 VB.NET Downloads
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
' Load the key for this One API integration from your application configuration.
http.SetRequestHeader("Authorization","ONE_API_KEY")
http.SetRequestHeader("Accept","application/json")
Dim firstPhone As String = "FIRST_PHONE_NUMBER"
Dim secondPhone As String = "SECOND_PHONE_NUMBER"
Dim body As New Chilkat.JsonObject
body.UpdateString("messages[0].channel","sms")
body.UpdateString("messages[0].to",firstPhone)
body.UpdateString("messages[0].content","Your appointment with Lee is at 10:00.")
body.UpdateString("messages[0].clientMessageId","appt-1042")
body.UpdateString("messages[1].channel","sms")
body.UpdateString("messages[1].to",secondPhone)
body.UpdateString("messages[1].content","Your appointment with Sam is at 14:30.")
body.UpdateString("messages[1].clientMessageId","appt-1043")
Dim resp As New Chilkat.HttpResponse
Dim sent As Boolean = http.HttpJson("POST","https://platform.clickatell.com/v1/message",body,"application/json",resp)
If (resp.StatusCode = 0) Then
Debug.WriteLine("No HTTP response. Check the message report before resending.")
Exit Sub
End If
Dim reply As New Chilkat.JsonObject
Dim parsed As Boolean = reply.Load(resp.BodyStr)
If ((sent <> True) Or ((resp.StatusCode <> 202) And (resp.StatusCode <> 207))) Then
Debug.WriteLine("Send returned HTTP " & resp.StatusCode)
If (reply.HasMember("error.description") = True) Then
Debug.WriteLine(reply.StringOf("error.description"))
End If
Exit Sub
End If
If (reply.HasMember("error.code") = True) Then
If (reply.IsNullOf("error.code") <> True) Then
Debug.WriteLine("Submission error " & reply.StringOf("error.code") & " " & reply.StringOf("error.description"))
Exit Sub
End If
End If
' Look up each submitted appointment in the reply using its unique recipient.
' This works even if the result order changes or clientMessageId is absent.
Dim results As New Chilkat.JsonObject
Dim i As Integer = 0
While (i < 2)
body.I = i
Dim appointment As String = body.StringOf("messages[i].clientMessageId")
Dim phone As String = body.StringOf("messages[i].to")
Dim result As New Chilkat.JsonObject
Dim found As Boolean = reply.FindRecord2("messages","to",phone,True,result)
results.I = i
results.UpdateString("appointments[i].clientMessageId",appointment)
If ((found <> True) Or (result.JsonTypeOf("accepted") <> 5)) Then
results.UpdateString("appointments[i].outcome","unknown")
Debug.WriteLine(appointment & " has no confirmed result.")
Else
If (result.BoolOf("accepted") = True) Then
results.UpdateString("appointments[i].outcome","accepted")
If (result.JsonTypeOf("apiMessageId") = 1) Then
results.UpdateString("appointments[i].apiMessageId",result.StringOf("apiMessageId"))
End If
Debug.WriteLine(appointment & " accepted.")
Else
results.UpdateString("appointments[i].outcome","rejected")
results.UpdateString("appointments[i].reason",result.StringOf("error.description"))
Debug.WriteLine(appointment & " rejected: " & result.StringOf("error.description"))
End If
End If
i = i + 1
End While
' This demo writes a snapshot. In an application, update the two appointment records.
Dim saved As Boolean = results.WriteFile("appointment-send-results.json")
If (saved <> True) Then
Debug.WriteLine("Could not save the results. Reconcile the submitted messages before retrying.")
Exit Sub
End If
Debug.WriteLine("Saved appointment-send-results.json")