Sample code for 30+ languages & platforms
VB.NET 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 VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
'  Obtain these credentials from the application's private configuration.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.BasicAuth = True
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"

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

Dim req As New 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")

Dim resp As New Chilkat.HttpResponse
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
    Debug.WriteLine("No response from Twilio. Check connectivity and TLS settings.")
    Exit Sub
End If

Dim result As New Chilkat.JsonObject
Dim parsed As Boolean = result.Load(resp.BodyStr)
If ((success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
    Debug.WriteLine("Twilio returned HTTP " & resp.StatusCode)
    If ((parsed = True) And (result.JsonTypeOf("code") = 2)) Then
        Debug.WriteLine("Twilio error code: " & result.IntOf("code"))
    End If

    Exit Sub
End If

If ((parsed <> True) Or (result.JsonTypeOf("status") <> 1)) Then
    Debug.WriteLine("Verification status missing from the response.")
    Exit Sub
End If

Dim status As String = result.StringOf("status")
If (status <> "pending") Then
    Debug.WriteLine("Verification status: " & status)
    Exit Sub
End If

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

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