VBScript Requires Chilkat v11.0.0+
VBScript
Send an SMS with Twilio
See more Twilio Examples
Submit an SMS with the sender, recipient, and text as form fields. This example starts with Twilio test credentials and its successful test sender. Twilio simulates the submission without sending or billing for a message. Test credentials and test numbers.
For live SMS, use the live Account SID in the URL, authenticate with an API key SID and secret, and use an SMS-capable Twilio sender and a recipient in E.164 format. HTTP 201 creates the message. Save its SID to check delivery status later.
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
http.BasicAuth = 1
' Use the test Account SID and test Auth Token from the Twilio Console.
accountSid = "YOUR_TEST_ACCOUNT_SID"
http.Login = accountSid
http.Password = "YOUR_TEST_AUTH_TOKEN"
set url = CreateObject("Chilkat.StringBuilder")
success = url.Append("https://api.twilio.com/2010-04-01/Accounts/")
success = url.Append(accountSid)
success = url.Append("/Messages.json")
' Add raw field values. Chilkat form-encodes them, including the + in a phone number.
set req = CreateObject("Chilkat.HttpRequest")
req.HttpVerb = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.AddParam "From","+15005550006"
req.AddParam "To","+12025550123"
req.AddParam "Body","Hello from Twilio!"
set resp = CreateObject("Chilkat.HttpResponse")
set reply = CreateObject("Chilkat.JsonObject")
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
outFile.WriteLine(http.LastErrorText)
WScript.Quit
End If
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or (resp.StatusCode <> 201)) Then
outFile.WriteLine("HTTP " & resp.StatusCode)
If ((parsed = 1) And (reply.HasMember("code") = 1)) Then
outFile.WriteLine("Twilio error " & reply.IntOf("code") & ": " & reply.StringOf("message"))
End If
WScript.Quit
End If
If (parsed <> 1) Then
outFile.WriteLine("Expected a JSON response.")
WScript.Quit
End If
If ((reply.JsonTypeOf("sid") <> 1) Or (reply.JsonTypeOf("status") <> 1)) Then
outFile.WriteLine("The create response is missing the message SID or status.")
WScript.Quit
End If
outFile.WriteLine("Message SID: " & reply.StringOf("sid"))
outFile.WriteLine("Initial status: " & reply.StringOf("status"))
outFile.Close