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

Send an SMS verification code with Twilio Verify

See more Twilio Examples

Live SMS. When a user requests a code, pass their phone number in E.164 format (for example, +12025550123) and select the SMS channel. Create a Verify Service in the Twilio Console first. Supply its VA service SID and an API key with access to that service. For a live test, use a phone you control. Messaging and verification charges may apply.

Twilio generates the code and sends it to the phone. A pending response means the application can prompt for the code. Save the returned VE verification SID with the user and phone number that initiated the request, then use it to check the code entered by the user.

Twilio Verify API reference

Chilkat VBScript Downloads

VBScript
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.
'  Obtain these credentials from the application's private configuration.
set http = CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.BasicAuth = 1
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"

'  Both requests use the same Verify Service SID (VA...).
set url = CreateObject("Chilkat.StringBuilder")
success = url.Append("https://verify.twilio.com/v2/Services/")
success = url.Append("YOUR_VERIFY_SERVICE_SID")
success = url.Append("/Verifications")

set req = CreateObject("Chilkat.HttpRequest")
req.HttpVerb = "POST"
req.ContentType = "application/x-www-form-urlencoded"
'  Supply the number the user asked to verify. AddParam encodes the leading plus sign.
req.AddParam "To","PHONE_NUMBER_IN_E164_FORMAT"
req.AddParam "Channel","sms"

set resp = CreateObject("Chilkat.HttpResponse")
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
    outFile.WriteLine("No response from Twilio. Check connectivity and TLS settings.")
    WScript.Quit
End If

set result = CreateObject("Chilkat.JsonObject")
parsed = result.Load(resp.BodyStr)
If ((success <> 1) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
    outFile.WriteLine("Twilio returned HTTP " & resp.StatusCode)
    If ((parsed = 1) And (result.JsonTypeOf("code") = 2)) Then
        outFile.WriteLine("Twilio error code: " & result.IntOf("code"))
    End If

    WScript.Quit
End If

If ((parsed <> 1) Or (result.JsonTypeOf("status") <> 1)) Then
    outFile.WriteLine("Verification status missing from the response.")
    WScript.Quit
End If

status = result.StringOf("status")
If (status <> "pending") Then
    outFile.WriteLine("Verification status: " & status)
    WScript.Quit
End If

If ((result.JsonTypeOf("sid") <> 1) Or (result.StringOf("sid") = "")) Then
    outFile.WriteLine("The pending response did not include a verification SID.")
    WScript.Quit
End If

'  Save this SID with the pending attempt before prompting the user for the code.
outFile.WriteLine("Pending verification SID: " & result.StringOf("sid"))

outFile.Close