Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Verify Phone Verification API

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

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.

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

URL

Name Type Description
FORMAT String The format to expect back from the REST API call. json or xml.

PARAMETERS

Name Type Description
via String The method of delivering the code to the user. sms or call. (🏢 not PII )
country_code Integer The phone's country code. (🏢 not PII )
phone_number String The phone number to send the verification code. (📇 PII )
locale String (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_length Integer (optional) Optional value to change the number of verification digits sent. Default value is 4. Allowed values are 4-10. (🏢 not PII )
custom_code Integer (optional) Pass in a pre-generated code. Code length can be between 4-10 characters. Contact Twilio Sales to have this feature enabled. (🏢 not PII )
        
        
        
        

        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.

        Supported Languages (Recommended)

        Please reference Supported Languages for full documentation. We support the format country-region as described in IETF's BPC 47. If no region is given (or supported) there will be a default by country. Supported languages for the locale parameter are af, ar, ca, zh, zh-CN, zh-HK, hr, cs, da, nl, en, fi, fr, de, el, he, hi, hu, id, it, ja, ko, ms, nb, pl, pt-BR, pt, ro, ru, es, sv, tl, th, tr, vi.

        For more information, please reference our full guide to Supported Languages.

        Custom Verification Codes (Optional)

        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 and we'll help you enable this option.

              
              
              
              

              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

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

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

              URL

              Name Type Description
              FORMAT String The format to expect back from the REST API call. json, or xml.

              PARAMETERS

              Name Type Description
              country_code Integer The phone's country code. (🏢 not PII )
              phone_number String The phone number to send the verification code. (📇 PII )
              verification_code String The verification code from the user that is being validated. (🏢 not PII )
                    
                    
                    
                    

                    Get the Status of a Verification Code Sent to the User

                    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.

                    GET https://api.authy.com/protected/{FORMAT}/phones/verification/status
                    
                    Name Type Description
                    FORMAT String The format to expect back from the REST API call. json, or xml.

                    PARAMETERS

                    Name Type Description
                    uuid String The uuid from the original request. (🏢 not PII )
                    country_code Integer (Optional) The phone's country code. Alternative to uuid when combined with phone_number. (🏢 not PII )
                    phone_number String (Optional) The phone number to send the verification code. Alternative to uuid when combined with country_code. (📇 PII )

                    Response

                    Name Type Description
                    status String The status of the original request to the user. expired, verified or pending. (🏢 not PII )
                    seconds_to_expire Integer The amount of time in seconds remaining before the verification code expires. (🏢 not PII )
                    success Boolean Returns true if the request was successful. (🏢 not PII )
                    message String A message indicating what happened with the request. (🏢 not PII )
                          
                          
                          
                          

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

                          Please note: checking the status with country_code and phone_number only works for pending verifications. If the request is not pending the response will indicate that No pending verifications for +1 987-654-3210 found with no additional status information.

                                
                                
                                
                                

                                Status Check Rate limits

                                You may request the status of a phone verification no more than:

                                • 60 requests in one minute
                                • 180 requests in one hour
                                • 250 requests in one day
                                Rate this page:

                                Need some help?

                                We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.