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

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

Clickatell API reference

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
'  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 Chilkat.JsonObject
body.UpdateString("messages[0].channel","sms")
body.UpdateString("messages[0].to","PHONE_NUMBER")
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 = ""
If (sender <> "") Then
    body.UpdateString("messages[0].from",sender)
End If

Dim resp As New Chilkat.HttpResponse
success = http.HttpJson("POST","https://platform.clickatell.com/v1/message",body,"application/json",resp)
If (resp.StatusCode = 0) Then
    Debug.WriteLine("The send outcome is unknown. 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 ((success <> True) Or ((resp.StatusCode <> 202) And (resp.StatusCode <> 207))) Then
    Debug.WriteLine("Clickatell returned HTTP " & resp.StatusCode)
    If (parsed = True) Then
        If (reply.HasMember("error.description") = True) Then
            Debug.WriteLine(reply.StringOf("error.description"))
        End If

    End If

    Exit Sub
End If

If (parsed <> True) Then
    Debug.WriteLine("Expected a JSON response.")
    Exit Sub
End If

'  A request-level error applies to the submission as a whole.
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

Dim count As Integer = reply.SizeOfArray("messages")
If (count <= 0) Then
    Debug.WriteLine("No recipient results returned. Check the message report before resending.")
    Exit Sub
End If

Dim i As Integer = 0
While (i < count)
    reply.I = i
    Dim resultNumber As Integer = i + 1
    '  JsonTypeOf returns 5 for a JSON boolean.
    If (reply.JsonTypeOf("messages[i].accepted") <> 5) Then
        Debug.WriteLine("Result " & resultNumber & " has no acceptance flag.")
    Else
        If (reply.BoolOf("messages[i].accepted") = True) Then
            Dim messageId As String = reply.StringOf("messages[i].apiMessageId")
            If ((reply.JsonTypeOf("messages[i].apiMessageId") <> 1) Or (messageId = "")) Then
                Debug.WriteLine("Result " & resultNumber & " was accepted without a tracking ID.")
            Else
                Debug.WriteLine("Result " & resultNumber & " accepted. Message ID: " & messageId)
            End If

        Else
            Debug.WriteLine("Result " & resultNumber & " rejected: " & reply.StringOf("messages[i].error.code") & "  " & reply.StringOf("messages[i].error.description"))
        End If

    End If

    i = i + 1
End While