Telnyx Verify helps to deliver a 2FA token to any mobile number and verify that token using Telnyx V2 API
In this tutorial, you’ll learn how to deliver a 2FA token to any mobile number and verify that token using the Telnyx v2 API. Examples are provided in curl, Node.js, Python, Ruby, Go, Java, .NET, and PHP.
There are currently three verification methods available:
sms - the verification code is sent in a custom or default templated message.
call - the code is spoken aloud in a custom or default templated message when the user answers the call.
flashcall - the verification code is embedded in the caller ID of a brief “flash” call (the call rings once and hangs up). The user’s app extracts the code automatically.
A Verify Profile contains several important configurations that you’ll use when sending 2-factor authentication messages and receiving responses. Before you send any 2FA messages, you need a profile to go with them.Each profile can have one of each verification method configured. It is recommended that if you wish to configure multiple applications, you use a different profile for each one.In the below example we will set up a verification profile that can use SMS using a selected message template and speech to text calling.
{ "data": [ { "id": "0abb5b4f-459f-445a-bfcd-488998b7572d", "text": "Your {{app_name}} verification code is: {{code}}." }, { "id": "2ca3f1da-5621-4aa6-ae56-df21caff79e0", "text": "{{code}} is your verification code for {{app_name}}." }, { "id": "33dfb056-6c1b-40bd-920e-4243e01248a5", "text": "Your {{app_name}} verification code is: {{code}}. Do not share this code with anyone; our employees will never ask for the code." }, { "id": "46acd63c-be57-4993-ae8d-0e4067ad1d57", "text": "Your {{app_name}} verification code is: {{code}}. This code will expire in {{default_verification_timeout_secs}} minutes." }, { "id": "723ead5e-ada6-4c29-a962-349170866187", "text": "{{code}} is your verification code for {{app_name}}. This code will expire in {{default_verification_timeout_secs}} minutes." }, { "id": "88d0781f-f4c7-4b78-8d0a-1f3e4de78b5e", "text": "Your {{app_name}} verification code is: {{code}}. This code will expire in {{default_verification_timeout_secs}} minutes. Do not share this code with anyone; our employees will never ask for the code." } ]}
If not selected then the default template is “Your verification code is {code}.”
Want to use your own branded verification messages? You can now create custom templates that match your brand voice and compliance requirements.
Don’t forget to set your TELNYX_API_KEY environment variable or replace YOUR_API_KEY in the curl examples.
Take note of the profile’s id that’s returned to you, you’ll need it to send 2FA verifications. At any time, you can access all of your created Verify Profiles by API as well.You are now ready to send 2-factor authentication messages!
To send a verification attempt, you need the Verify Profile ID, the phone number that will receive the message, and the verification type. Choose the method that best fits your use case:
SMS
Call
SMS verification sends a code via text message. This is the most common method with the widest global coverage.
User experience: The user receives a text message with a numeric code (e.g., “Your verification code is: 17686”). They enter this code in your application.
Call verification speaks the code aloud when the user answers. Useful when the user cannot receive SMS (landlines, VoIP) or in regions with unreliable SMS delivery.Profile configuration for call:When creating your verify profile, include the call configuration:
User experience: The user receives a phone call. An automated voice reads the verification code aloud (e.g., “Your verification code is 1-7-6-8-6”). The code is repeated twice. The user then enters the code in your application.
DTMF confirmation: You can optionally enable DTMF confirmation, where the user enters the code on their phone keypad during the call instead of typing it in your app. See the DTMF Confirmation guide for details.
Fallback strategy: Configure multiple methods in your verify profile. Start with SMS (fastest and widest coverage), fall back to call if SMS fails. For mobile apps, consider flashcall as a zero-friction primary method with SMS as fallback.
A response_code of "accepted" confirms the code matches. Other possible values:
Response Code
Meaning
accepted
Code is correct - verification successful
rejected
Code is incorrect
expired
Verification timed out (exceeded timeout_secs)
max_attempts_exceeded
Too many incorrect attempts
Telnyx Verify supports webhooks to receive instant notifications when users complete verification, eliminating the need for polling. This enables event-driven workflows for faster user experiences.Learn more: Receiving Webhooks for Telnyx Verify