Sample code for 30+ languages & platforms
Visual Basic 6.0 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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
'  Obtain these credentials from the application's private configuration.
Dim http As New ChilkatHttp
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...).
Dim url As New ChilkatStringBuilder
success = url.Append("https://verify.twilio.com/v2/Services/")
success = url.Append("YOUR_VERIFY_SERVICE_SID")
success = url.Append("/Verifications")

Dim req As New ChilkatHttpRequest
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 ChilkatHttpResponse
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
    Debug.Print "No response from Twilio. Check connectivity and TLS settings."
    Exit Sub
End If

Dim result As New ChilkatJsonObject
Dim parsed As Long
parsed = result.Load(resp.BodyStr)
If ((success <> 1) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
    Debug.Print "Twilio returned HTTP " & resp.StatusCode
    If ((parsed = 1) And (result.JsonTypeOf("code") = 2)) Then
        Debug.Print "Twilio error code: " & result.IntOf("code")
    End If

    Exit Sub
End If

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

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

If ((result.JsonTypeOf("sid") <> 1) Or (result.StringOf("sid") = "")) Then
    Debug.Print "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.Print "Pending verification SID: " & result.StringOf("sid")