Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Verify Phone Verification API V1


(warning)

Warning

Verify v1 API has reached End of Sale. It is now closed to new customers and will be fully deprecated in the future.

For new development, we encourage you to use the Verify v2 API. v2 has an improved developer experience and new features, including:

  • Twilio helper libraries in multiple languages
  • PSD2 Secure Customer Authentication Support
  • Improved Visibility and Insights

Existing customers will not be impacted at this time until Verify v1 API has reached End of Life. For more information about migration, see Migrating from 1.x to 2.x.

The Twilio Verify REST API allows you to verify that a user has a claimed device in their possession. The API lets you request a verification code to be sent to the user and to check that a received code is valid.

Phone verification is an important first step in your online relationship with a user. To learn more about best practices and recommended registration flows, please consult Twilio Verify Best Practices.


Send a Verification Code

send-a-verification-code page anchor

To verify a user's phone number, you will start by requesting to send a verification code to their device. Each verification code is valid for 10 minutes. Subsequent calls to the API before the code has expired will send the same verification code. You cannot modify the amount of time a verification code is valid. You can query the status endpoint to check if a verification code is still valid.

Note that you may use dashes, periods, spaces or nothing to format a phone number.


_10
POST https://api.authy.com/protected/{FORMAT}/phones/verification/start

URL

url page anchor
NameTypeDescription
FORMATStringThe format to expect back from the REST API call. json or xml.
NameTypeDescription
viaStringThe method of delivering the code to the user. sms or call. (🏢 not PII )
country_codeIntegerThe phone's country code. (🏢 not PII )
phone_numberStringThe phone number to send the verification code. (📇 PII )
localeString (recommended)The language of the message received by user. If no region is given (or supported) there will be a default by country. Depending on the country, this will either be the official language of the country or English. We highly recommend that you test your region or use the locale parameter to ensure that your desired language is used. See supported languages for a list of available options. (🏢 not PII )
code_lengthInteger (optional)Optional value to change the number of verification digits sent. Default value is 4. Allowed values are 4-10. (🏢 not PII )
custom_codeInteger (optional)Pass in a pre-generated code. Code length can be between 4-10 characters. Contact Twilio Sales(link takes you to an external page) to have this feature enabled. (🏢 not PII )

Start a phone verification.

start-a-phone-verification page anchor
Node.js
Python
C#
PHP
Ruby
curl

_12
// npm install authy
_12
const authy = require("authy")("YOUR_AUTHY_API_KEY");
_12
_12
authy
_12
.phones()
_12
.verification_start("5551234567", "1", "sms", function(err, res) {
_12
if (err) {
_12
console.log(err);
_12
}
_12
_12
console.log(res.message);
_12
});

Output

_10
{
_10
"carrier": "AT&T Wireless",
_10
"is_cellphone": true,
_10
"message": "Text message sent to +1 987-654-3210.",
_10
"seconds_to_expire": 599,
_10
"uuid": "b8ebcd40-1234-5678-3fb5-0e5d6a065904",
_10
"success": true
_10
}

(information)

Info

Please note: For some regions, we are unable to return carrier and cellphone data by default. You need to contact our support team to switch on those regions. More information on our support site.(link takes you to an external page)

Custom Verification Codes (Optional)

custom-verification-codes-optional page anchor

If you already have token generation and validation logic and would like to keep those systems in place, you can do so. We have a feature where you can submit your code to us and utilize our pre-screened message templates and localizations for both text and voice.

With this modified setup, you will be charged on each attempted customer verification (requests for a verification code). Due to situations like abandoned requests and users who eagerly request multiple codes, we typically see 30% more /start verifications than /check verifications. This means that you can expect to pay 30% more for this feature. Keep this in mind as you are considering your options.

If you're using custom verification codes you must also provide feedback that lets us know whether or not the user verified the code. This allows us to proactively monitor our global routing and stay operational. You can send feedback to our system with the Verify Feedback API.

Contact Twilio Sales(link takes you to an external page) and we'll help you enable this option.

Start a phone verification with custom code.

start-a-phone-verification-with-custom-code page anchor
curl

_10
curl -X POST 'https://api.authy.com/protected/json/phones/verification/start' \
_10
-H "X-Authy-API-Key: d57d919d11e6b221c9bf6f7c882028f9" \
_10
-d via='sms' \
_10
-d phone_number='987-654-3210' \
_10
-d country_code=1 \
_10
-d locale=en \
_10
-d custom_code=3333

Output

_10
{
_10
"carrier": "AT&T Wireless",
_10
"is_cellphone": true,
_10
"message": "Text message sent to +1 987-654-3210.",
_10
"seconds_to_expire": 599,
_10
"uuid": "b8ebcd40-1234-5678-3fb5-0e5d6a065904",
_10
"sms_id": "cafd7a60-6d03-1234-5678-0eb34144aeb2", # You'll use this ID to send feedback
_10
"success": true
_10
}

Following a request using custom_code you will then submit a request to our Feedback API. Head over to the Feedback API docs for example requests.


Check a Verification Code

check-a-verification-code page anchor

To check if a verification code is correct, pass the code along with the phone number to the API.


_10
GET https://api.authy.com/protected/{FORMAT}/phones/verification/check

NameTypeDescription
FORMATStringThe format to expect back from the REST API call. json, or xml.
NameTypeDescription
country_codeIntegerThe phone's country code. (🏢 not PII )
phone_numberStringThe phone number to send the verification code. (📇 PII )
verification_codeStringThe verification code from the user that is being validated. (🏢 not PII )

Check a Verification Code.

check-a-verification-code-1 page anchor
Node.js
Python
C#
PHP
Ruby
curl

_10
authy.phones().verification_check('111-111-1111', '1', '1234', function (err, res) {
_10
if (err) {
_10
// invalid token
_10
console.log(err);
_10
}
_10
_10
console.log(res);
_10
});

Output

_10
{
_10
"message":"Verification code is correct.",
_10
"success":true
_10
}


Get the Status of a Verification Code Sent to the User

get-the-status-of-a-verification-code-sent-to-the-user page anchor

Each verification code is valid for 10 minutes. Subsequent calls to the API before the code has expired will send the same verification code. Use this status API to determine how much time remains for an active or pending verification request.


_10
GET https://api.authy.com/protected/{FORMAT}/phones/verification/status

NameTypeDescription
FORMATStringThe format to expect back from the REST API call. json, or xml.
NameTypeDescription
uuidStringThe uuid from the original request. (🏢 not PII )
country_codeInteger (Optional)The phone's country code. Alternative to uuid when combined with phone_number. (🏢 not PII )
phone_numberString (Optional)The phone number to send the verification code. Alternative to uuid when combined with country_code. (📇 PII )
NameTypeDescription
statusStringThe status of the original request to the user. expired, verified or pending. (🏢 not PII )
seconds_to_expireIntegerThe amount of time in seconds remaining before the verification code expires. (🏢 not PII )
successBooleanReturns true if the request was successful. (🏢 not PII )
messageStringA message indicating what happened with the request. (🏢 not PII )

Check Verification Status using Verification UUID.

check-verification-status-using-verification-uuid page anchor
curl

_10
curl 'https://api.authy.com/protected/json/phones/verification/status?uuid=b8ebcd40-1234-5678-3fb5-0e5d6a065904' \
_10
-H "X-Authy-API-Key: d57d919d11e6b221c9bf6f7c882028f9"

Output

_10
{
_10
"message": "Phone Verification status.",
_10
"status": "verified",
_10
"seconds_to_expire": 474,
_10
"success": true
_10
}

This example checks the status of the request using country_code and phone_number.

Check Verification Status using Phone Number.

check-verification-status-using-phone-number page anchor
curl

_10
curl 'https://api.authy.com/protected/json/phones/verification/status?country_code=1&phone_number=987-654-3210' \
_10
-H "X-Authy-API-Key: d57d919d11e6b221c9bf6f7c882028f9"

Output

_10
{
_10
"message": "Phone Verification status.",
_10
"status": "pending",
_10
"seconds_to_expire": 598,
_10
"success": true
_10
}


Rate this page: