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 Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New ChilkatHttp
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"
Dim body As New ChilkatJsonObject
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.
Dim sender As String
sender = ""
If (sender <> "") Then
success = body.UpdateString("messages[0].from",sender)
End If
Dim resp As New ChilkatHttpResponse
success = http.HttpJson("POST","https://platform.clickatell.com/v1/message",body,"application/json",resp)
If (resp.StatusCode = 0) Then
Debug.Print "The send outcome is unknown. Check the message report before resending."
Exit Sub
End If
Dim reply As New ChilkatJsonObject
Dim parsed As Long
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or ((resp.StatusCode <> 202) And (resp.StatusCode <> 207))) Then
Debug.Print "Clickatell returned HTTP " & resp.StatusCode
If (parsed = 1) Then
If (reply.HasMember("error.description") = 1) Then
Debug.Print reply.StringOf("error.description")
End If
End If
Exit Sub
End If
If (parsed <> 1) Then
Debug.Print "Expected a JSON response."
Exit Sub
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
Debug.Print "Submission error " & reply.StringOf("error.code") & " " & reply.StringOf("error.description")
Exit Sub
End If
End If
Dim count As Long
count = reply.SizeOfArray("messages")
If (count <= 0) Then
Debug.Print "No recipient results returned. Check the message report before resending."
Exit Sub
End If
Dim i As Long
i = 0
Do While (i < count)
reply.I = i
Dim resultNumber As Long
resultNumber = i + 1
' JsonTypeOf returns 5 for a JSON boolean.
If (reply.JsonTypeOf("messages[i].accepted") <> 5) Then
Debug.Print "Result " & resultNumber & " has no acceptance flag."
Else
If (reply.BoolOf("messages[i].accepted") = 1) Then
Dim messageId As String
messageId = reply.StringOf("messages[i].apiMessageId")
If ((reply.JsonTypeOf("messages[i].apiMessageId") <> 1) Or (messageId = "")) Then
Debug.Print "Result " & resultNumber & " was accepted without a tracking ID."
Else
Debug.Print "Result " & resultNumber & " accepted. Message ID: " & messageId
End If
Else
Debug.Print "Result " & resultNumber & " rejected: " & reply.StringOf("messages[i].error.code") & " " & reply.StringOf("messages[i].error.description")
End If
End If
i = i + 1
Loop