Clickatell One API: Send an SMS and get its message ID
See more Clickatell Examples
Send one text using an SMS-enabled One API integration. Supply an international phone number starting with the country code, using digits only. For a US two-way integration, set from to its provisioned two-way number. With a test integration, use a registered test phone.
HTTP 202 means the submission was processed. Inspect accepted for each message. Save the returned apiMessageId with the application record and use it to look up delivery status. When a multi-message submission returns HTTP 207, check each result before retrying any rejected message.
Already using the SMS-only REST integration? Its documented request is POST /messages with the integration key in Authorization and a body such as {"content":"Test message","to":["PHONE_NUMBER"]}. One API has a different request body and a separate integration key. SMS API reference
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
' Supply the key for this One API integration from application configuration.
http.SetRequestHeader "Authorization","ONE_API_KEY"
http.SetRequestHeader "Accept","application/json"
set body = Server.CreateObject("Chilkat.JsonObject")
success = body.UpdateString("messages[0].channel","sms")
success = body.UpdateString("messages[0].to","PHONE_NUMBER")
success = body.UpdateString("messages[0].content","Test message: your order is ready.")
' For a two-way sender, supply the number provisioned on the integration.
sender = ""
If (sender <> "") Then
success = body.UpdateString("messages[0].from",sender)
End If
set resp = Server.CreateObject("Chilkat.HttpResponse")
success = http.HttpJson("POST","https://platform.clickatell.com/v1/message",body,"application/json",resp)
If (resp.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "The send outcome is unknown. Check the message report before resending.") & "</pre>"
Response.End
End If
set reply = Server.CreateObject("Chilkat.JsonObject")
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or ((resp.StatusCode <> 202) And (resp.StatusCode <> 207))) Then
Response.Write "<pre>" & Server.HTMLEncode( "Clickatell returned HTTP " & resp.StatusCode) & "</pre>"
If (parsed = 1) Then
If (reply.HasMember("error.description") = 1) Then
Response.Write "<pre>" & Server.HTMLEncode( reply.StringOf("error.description")) & "</pre>"
End If
End If
Response.End
End If
If (parsed <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON response.") & "</pre>"
Response.End
End If
' A request-level error applies to the submission as a whole.
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
count = reply.SizeOfArray("messages")
If (count <= 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No recipient results returned. Check the message report before resending.") & "</pre>"
Response.End
End If
i = 0
Do While (i < count)
reply.I = i
resultNumber = i + 1
' JsonTypeOf returns 5 for a JSON boolean.
If (reply.JsonTypeOf("messages[i].accepted") <> 5) Then
Response.Write "<pre>" & Server.HTMLEncode( "Result " & resultNumber & " has no acceptance flag.") & "</pre>"
Else
If (reply.BoolOf("messages[i].accepted") = 1) Then
messageId = reply.StringOf("messages[i].apiMessageId")
If ((reply.JsonTypeOf("messages[i].apiMessageId") <> 1) Or (messageId = "")) Then
Response.Write "<pre>" & Server.HTMLEncode( "Result " & resultNumber & " was accepted without a tracking ID.") & "</pre>"
Else
Response.Write "<pre>" & Server.HTMLEncode( "Result " & resultNumber & " accepted. Message ID: " & messageId) & "</pre>"
End If
Else
Response.Write "<pre>" & Server.HTMLEncode( "Result " & resultNumber & " rejected: " & reply.StringOf("messages[i].error.code") & " " & reply.StringOf("messages[i].error.description")) & "</pre>"
End If
End If
i = i + 1
Loop
%>
</body>
</html>