Phone Validation via API
Phone validation verifies a person’s ownership of a phone number by comparing the code they enter with the one that was sent to the phone. These are the countries we support OTP (one-time password) shipping to:
- Mexico (+52)
- United States (+1)
- Chile (+56)
- Colombia (+57)
- Peru (+51)
- Venezuela (+58)
- Brazil (+55)
- Ecuador (+593)
- Australia/Cocos/Christmas Island (+61)
Prerequisites
Before you begin, make sure you have the following:
- Truora API-Key: You should already have your Truora API-Key. If you don’t, set up an account and then go to Authentication to obtain your Truora API-key.
- Phone Number: If you already know the phone number you want to validate, please provide it yourself. Otherwise, request it from your user.
- Postman: Use Postman or any other collaboration tool for API development. Although it is not required to perform the integration, it will help perform tests along the way.
Truora provides a Postman collection online that includes the necessary tools to simplify the testing process.
1. Create Enrollment
Create a phone validation associated with an account. The account allows a user to be identified on the Truora platform and is represented by the account_id
.
The enrollment should only be done once per
phone_type
. If the user account already has aphone-verification
enrollment. Please proceed to create the validation directly.
Setup main Request Headers and Body
To configure the main request headers and body, follow these steps:
- Create a
POST
request tohttps://api.validations.truora.com/v1/enrollments
. - Set the Headers
Truora-API-Key
enter the value obtained in the step of get API Key.Content-Type
the value should beapplication/x-www-form-urlencoded
.
- Set required values for the request body
type
[Required]: Indicates the type of validation to be performed. Set this value tophone-verification
user_authorized
[Required]: This indicates that you have the authorization of the person to be verified. This is mandatory in order to comply with data protection laws. Value must be set totrue
in order to perform the validation.phone_number
[Required]: Phone number to be associated with the validation account on successful validation. Must include the country code (e.g., +57300XXXXXXX).phone_type
[Required]: Allowed:home
|office
|recover
. Specifies the label of the phone number to be associated with the validation account upon successful validation. You can associate up to three phone numbers with a user account. To do this, you must create a new enrollment by choosing a differentphone_type
each time.country
[Optional]: Allowed:CO
|CL
|MX
|BR
|VE
|PE
|EC
|AR
|US
. Origin country of the person to be validated.account_id
[Optional]: The account_id is a unique value assigned to each user in the system to distinguish them and access their information and processes. Only Account IDs following the regex pattern [a-zA-Z0-9_.-]+ are supported. Please go to Create an Account ID to learn more about it.
If everything goes well with the enrollment, you should receive a response similar to the following:
/v1/enrollments
Note: The
phone_type
,enrollment_id
andaccount_id
of the response on this endpoint will be used in later steps.
2. Get Enrollment
Allows searching for an enrollment in order to verify its progress, this step is optional.
The enrollment status will be success
or failure
depending on the internal verifications performed on the number.
-
Create a GET request to the endpoint
https://api.validations.truora.com/v1/enrollments/{{enrollment_id}}
. -
If everything goes well with the enrollment, you should receive a response similar to the following:
GET
/v1/enrollments/{{enrollment_id}} -
For Colombia, an additional verification is performed on the behavior of the line. A score ranging from 0 to 1 is obtained. The closer the score of the line is to 1, the indication is that the line has not been reported for suspicious activity. You should receive a response similar to the following:
/v1/enrollments/{{enrollment_id}}
-
If a number from a country not supported is sent, you will receive a response like this:
GET
/v1/enrollments/{{enrollment_id}} -
If an invalid number is sent, you will receive a response like this:
GET
/v1/enrollments/{{enrollment_id}}
3. Create validation
Setup main Request Headers and Body
To configure the main request headers and body, follow these steps:
-
Create a POST request to
https://api.validations.truora.com/v1/validations
. -
Set the Headers
Truora-API-Key
enter the value obtained in the step of get API Key.Content-Type
the value should beapplication/x-www-form-urlencoded
.
-
Set required values for the request body
type
[Required]: Indicates the type of validation to be performed. Set this value tophone-verification
verify_channel
[Required]: Allowed:sms
|call
|whatsapp
. Indicates the channel used to perform the verification. Some problems may occur when receiving the SMS due to external protocols of the mobile service providers, so we recommend giving an additional option to the users.*phone_locale
[Required]: Allowed:en
|es
|pt-BR
. Language used to perform the validation via the selected verification channel.phone_type
[Required]: Allowed:home
|office
|recover
. Specifies the label of the phone number to be associated with the validation account upon successful validation. The phone type must have already been enrolled.user_authorized
[Required]: This indicates that you have the authorization of the person to be verified. This is mandatory in order to comply with data protection laws. Value must be set totrue
in order to perform the validation.account_id
[Required]: Use the same account_id that was used in Create Enrollment.country
[Optional]: Allowed:CO
|MX
|BR
|CL
|PE
|VE
|EC
|US
|AU
. Origin country of the person to be validated.timeout
[Optional]: The time, in seconds, users will have to complete the validation. If omitted, the timeout from the client’s config will be used. The default value is 300 seconds (5 minutes), with a maximum of 600 seconds (10 minutes).
*If you set whatsapp
as the verify_channel
value, you must have your own WABA line and Activate it. Then, create your Outbound message of type OTP and Contact Support to provide your Outbound ID for inclusion in your process:
- This guide explains how to Create a WABA line and Activate it
- This guide explains how to Create an Outbound message and obtain your message´s Outbound ID. Follow the guide and select OTP in the Message Category.
- After the message is approved, Contact Support and provide the Outbound ID of your message to our team to include it in your process.
After setting the required values in the Request Body, if everything goes well with the Create Validation request, you should receive a response similar to the following:
/v1/validations
Note: The
validation_id
of the response on this endpoint will be used in later steps.
4. Perform Validation
Setup main Request Headers and Body
To configure the main request headers and body, follow these steps:
-
Create a POST request to
https://api.validations.truora.com/v1/validations/{{validation_id}}
. -
Set the Headers
Truora-API-Key
enter the value obtained in the step of get API Key.Content-Type
the value should beapplication/x-www-form-urlencoded
.
-
Set required values for the request body
type
[Required]: Indicates the type of validation to be performed. Set this value tophone-verification
token
[Required]: Validation code sent via sms, voice call or WhatsApp.
If everything goes well with the Perform Validation, you should receive a response similar to the following:
/v1/validations/{{validation_id}}
By default, the user will have 2 retries to enter the code. You can see the remaining retries in the field
remaining_retries
.
5. Get Validation
This API endpoint allows you to retrieve the current status and information of a validation. The validation_status
begins as pending
. Upon completion, the validation can either be success
or failure
.
-
To obtain the validation results, send a GET request to the endpoint
https://api.validations.truora.com/v1/validations/{{validation_id}}
, wherevalidation_id
is the identifier returned in the Create validation request. -
If you want to obtain details such as the inputs of the validation, you can send the query parameter
show_details
with the value oftrue
. -
Once executed, if the validation is still processing,
validation_status
will bepending
and you will receive a response similar to the following:GET
/v1/validations/{{validation_id}} -
When the validation is completed successfully,
validation_status
will besuccess
and you will receive a response similar to the following:GET
/v1/validations/{{validation_id}} -
If you send the query parameter
show_details
, you will receive a response similar to the following:GET
/v1/validations/{{validation_id}}?show_details=true
Declined and Expired reasons
Whenever a validation fails due to inconsistencies in the validation process or expires in the validation process, the API provides a reason to indicate why the validation was declined or expired:
- To learn more about the possible declined reasons, please visit the Declined Reasons section.
- To learn more about the possible expired reason, please visit Expired Reasons section.
Additional configurations
You can configure other parameters to improve the behavior of the validators and the user experience. Please see the Config Validator section for more information on customization.
Getting results automatically (Webhooks)
To get validation results automatically, you must subscribe webhooks. For more information, please see Webhooks section.