VBScript Requires Chilkat v11.0.0+
VBScript
Clickatell HTTP API: Send an SMS with query parameters
See more Clickatell Examples
Use an SMS integration configured for HTTP in the Clickatell Portal. The endpoint takes apiKey, to, and content as query parameters. Pass raw values to Chilkat so it can encode spaces, ampersands, and other reserved characters. Supply a country code and phone number as digits. Set from when your two-way integration requires a sender.
The URL contains the API key, recipient, and message text. Keep full request URLs out of logs and browser history. Check the per-message result after HTTP 202. If the connection is interrupted, check the Portal message report before resending. For the header-authenticated JSON workflow, see Send an SMS with One API.
Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
' Use the key issued for this HTTP integration. Chilkat encodes each query value.
set query = CreateObject("Chilkat.HttpRequest")
query.HttpVerb = "GET"
query.AddHeader "Accept","application/json"
query.AddParam "apiKey","HTTP_API_KEY"
query.AddParam "to","PHONE_NUMBER"
query.AddParam "content","Test message: pickup between 2 & 4."
sender = ""
If (sender <> "") Then
query.AddParam "from",sender
End If
set resp = CreateObject("Chilkat.HttpResponse")
success = http.HttpReq("https://platform.clickatell.com/messages/http/send",query,resp)
If (resp.StatusCode = 0) Then
outFile.WriteLine("The send outcome is unknown. Check the message report before resending.")
WScript.Quit
End If
set reply = CreateObject("Chilkat.JsonObject")
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or ((resp.StatusCode <> 202))) Then
outFile.WriteLine("Clickatell returned HTTP " & resp.StatusCode)
If (parsed = 1) Then
If (reply.HasMember("errorDescription") = 1) Then
outFile.WriteLine(reply.StringOf("errorDescription"))
End If
End If
WScript.Quit
End If
If (parsed <> 1) Then
outFile.WriteLine("Expected a JSON response.")
WScript.Quit
End If
' A request-level error applies to the submission as a whole.
If (reply.HasMember("errorCode") = 1) Then
If (reply.IsNullOf("errorCode") <> 1) Then
outFile.WriteLine("Submission error " & reply.StringOf("errorCode") & " " & reply.StringOf("errorDescription"))
WScript.Quit
End If
End If
count = reply.SizeOfArray("messages")
If (count <= 0) Then
outFile.WriteLine("No recipient results returned. Check the message report before resending.")
WScript.Quit
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
outFile.WriteLine("Result " & resultNumber & " has no acceptance flag.")
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
outFile.WriteLine("Result " & resultNumber & " was accepted without a tracking ID.")
Else
outFile.WriteLine("Result " & resultNumber & " accepted. Message ID: " & messageId)
End If
Else
outFile.WriteLine("Result " & resultNumber & " rejected: " & reply.StringOf("messages[i].errorCode") & " " & reply.StringOf("messages[i].errorDescription"))
End If
End If
i = i + 1
Loop
outFile.Close