Sample code for 30+ languages & platforms
Classic ASP 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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
'  Obtain these credentials from the application's private configuration.
set http = Server.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 = Server.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 = Server.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 = Server.CreateObject("Chilkat.HttpResponse")
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( "No response from Twilio. Check connectivity and TLS settings.") & "</pre>"
    Response.End
End If

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

    Response.End
End If

If ((parsed <> 1) Or (result.JsonTypeOf("status") <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Verification status missing from the response.") & "</pre>"
    Response.End
End If

status = result.StringOf("status")
If (status <> "pending") Then
    Response.Write "<pre>" & Server.HTMLEncode( "Verification status: " & status) & "</pre>"
    Response.End
End If

If ((result.JsonTypeOf("sid") <> 1) Or (result.StringOf("sid") = "")) Then
    Response.Write "<pre>" & Server.HTMLEncode( "The pending response did not include a verification SID.") & "</pre>"
    Response.End
End If

'  Save this SID with the pending attempt before prompting the user for the code.
Response.Write "<pre>" & Server.HTMLEncode( "Pending verification SID: " & result.StringOf("sid")) & "</pre>"

%>
</body>
</html>