Classic ASP Requires Chilkat v11.0.0+
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
' Load the key for this One API integration from your application configuration.
http.SetRequestHeader "Authorization","ONE_API_KEY"
http.SetRequestHeader "Accept","application/json"
firstPhone = "FIRST_PHONE_NUMBER"
secondPhone = "SECOND_PHONE_NUMBER"
set body = Server.CreateObject("Chilkat.JsonObject")
success = body.UpdateString("messages[0].channel","sms")
success = body.UpdateString("messages[0].to",firstPhone)
success = body.UpdateString("messages[0].content","Your appointment with Lee is at 10:00.")
success = body.UpdateString("messages[0].clientMessageId","appt-1042")
success = body.UpdateString("messages[1].channel","sms")
success = body.UpdateString("messages[1].to",secondPhone)
success = body.UpdateString("messages[1].content","Your appointment with Sam is at 14:30.")
success = body.UpdateString("messages[1].clientMessageId","appt-1043")
set resp = Server.CreateObject("Chilkat.HttpResponse")
sent = http.HttpJson("POST","https://platform.clickatell.com/v1/message",body,"application/json",resp)
If (resp.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Check the message report before resending.") & "</pre>"
Response.End
End If
set reply = Server.CreateObject("Chilkat.JsonObject")
parsed = reply.Load(resp.BodyStr)
If ((sent <> 1) Or ((resp.StatusCode <> 202) And (resp.StatusCode <> 207))) Then
Response.Write "<pre>" & Server.HTMLEncode( "Send returned HTTP " & resp.StatusCode) & "</pre>"
If (reply.HasMember("error.description") = 1) Then
Response.Write "<pre>" & Server.HTMLEncode( reply.StringOf("error.description")) & "</pre>"
End If
Response.End
End If
If (reply.HasMember("error.code") = 1) Then
If (reply.IsNullOf("error.code") <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Submission error " & reply.StringOf("error.code") & " " & reply.StringOf("error.description")) & "</pre>"
Response.End
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.
set results = Server.CreateObject("Chilkat.JsonObject")
i = 0
Do While (i < 2)
body.I = i
appointment = body.StringOf("messages[i].clientMessageId")
phone = body.StringOf("messages[i].to")
set result = Server.CreateObject("Chilkat.JsonObject")
found = reply.FindRecord2("messages","to",phone,1,result)
results.I = i
success = results.UpdateString("appointments[i].clientMessageId",appointment)
If ((found <> 1) Or (result.JsonTypeOf("accepted") <> 5)) Then
success = results.UpdateString("appointments[i].outcome","unknown")
Response.Write "<pre>" & Server.HTMLEncode( appointment & " has no confirmed result.") & "</pre>"
Else
If (result.BoolOf("accepted") = 1) Then
success = results.UpdateString("appointments[i].outcome","accepted")
If (result.JsonTypeOf("apiMessageId") = 1) Then
success = results.UpdateString("appointments[i].apiMessageId",result.StringOf("apiMessageId"))
End If
Response.Write "<pre>" & Server.HTMLEncode( appointment & " accepted.") & "</pre>"
Else
success = results.UpdateString("appointments[i].outcome","rejected")
success = results.UpdateString("appointments[i].reason",result.StringOf("error.description"))
Response.Write "<pre>" & Server.HTMLEncode( appointment & " rejected: " & result.StringOf("error.description")) & "</pre>"
End If
End If
i = i + 1
Loop
' This demo writes a snapshot. In an application, update the two appointment records.
saved = results.WriteFile("appointment-send-results.json")
If (saved <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not save the results. Reconcile the submitted messages before retrying.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Saved appointment-send-results.json") & "</pre>"
%>
</body>
</html>