Phone validation and verification are crucial for authenticating a person in account registration and sign-in processes. Validating the phone number is the first step in establishing the trust as it gives the first warning for anyone attempting illegal entry. Since email verification is not sufficient to avoid scammers and fraudsters, phone verification adds an extra layer of security. There are billions of phone users worldwide, and they modify phones frequently, making the verification difficult. Hence, an API that explicitly provides this capability will be an ideal solution.
So, if you are a website owner, you can integrate such phone validation API as part of your phone verification processes instead of building them from scratch. The Veriphone API from RapidAPI is one such simple API that offers you this functionality.
What is the Veriphone API?
Veriphone API is a free, fast, and reliable JSON API that instantly validates any phone number of any country or region in the world. When you specify a phone number in a valid international or local format, it will parse, format, and validate that phone number. The API also provides other helpful information like carrier, phone number type, and region, apart from the validity. Additionally, it can automatically set the default country based on the IP address of the request.
This API is a freemium API that is available with four different subscription plans. It supports various programming languages, including Python, PHP, Ruby, and Javascript. This article will dig deeper into the details of this API and show how to use it with multiple programming languages.
How does the Veriphone API work?
Veriphone API works using simple API logic in which It sends a request to a specific endpoint and obtains the necessary output as the response. When sending a request, it includes x-RapidAPI-key and host as authentication parameters so that the server can identify it as a valid request. The body of the API request contains the phone number and the optional parameters like country code and phone type that users specify. Once the API server has received the request, it will process it using the back-end application with the databases. Finally, the server will send back the phone number information requested by the client in JSON format.
Target Audience for the Veriphone API
Web Developers
Web Application developers can easily integrate Veriphone API for account creation and sign-in functionalities. They can quickly call this API when validating phone numbers in account creation forms and validate them promptly. Apart from that, they can also build a complete phone verification process by combining this API with an SMS API. You can also use this API to develop a phone number lookup service where you can simply return information about a particular phone number to help detect spammers. Since this API offers four pricing plans, they can select the best option based on their expected user capacity.
Learners
Veriphone API is easy to learn and integrate using many programming languages. It comes with a free plan while its Pro plan only costs $30 per month. Therefore, anyone who learns about APIs or wants to keep an up-to-date national and international phone number database can make use of this API at a low cost.
How to connect to the Veriphone API Tutorial – Step by Step
Step 1 – Sign up and Get a RapidAPI Account.
RapidAPI is the world’s largest API marketplace which is used by more than a million developers worldwide. You can use RapidAPI to search and connect to thousands of APIs using a single SDK, API key, and Dashboard.
Visit rapidapi.com and click on the Sign Up icon to create a RapidAPI account. You can use your Google, Github, or Facebook account for Single Sign-on (SSO) or create an account manually.
Step 2 – Search the API Marketplace
Navigate to the Marketplace and search for “Veriphone API.” Then, select the ‘Veriphone’ API from the search results.
Step 3 – Subscribe to the API
For the purpose of this article, we select the free basic plan of the Veriphone API. We need to subscribe to this API to use it. Navigate to the “pricing” section of the API and subscribe to your preferred plan. Then, simply click on the “subscribe” button to activate the subscription.
Step 4 – Test the API Subscription
After subscribing to the API, you should run a test for its endpoints. For that, navigate to the ‘Endpoints’ section of the API page, which shows all the available endpoints.
Next, select the endpoint you want to test and add the required values for the parameters. Each API endpoint provides code snippets in multiple languages and automatically adds the API keys.
Finally, click on the “Test Endpoint” Button to test the endpoint. You will get the response with a 200 status code upon successful testing of an API endpoint. On the other hand, it will output an error code and message if there is an error in the request.
The Veriphone API Endpoints
Currently, RapidAPI provides two HTTP GET endpoints for the Veriphone API.
/example
You can get an example phone number for any country through this API endpoint. There are two optional parameters that you can specify when using this endpoint. The first parameter, ‘type,’ specifies the type of the example phone number to return. For example, if you want a landline number, specify it as ‘fixedline,’ and for a mobile phone number, use ‘mobile.’ Other values that can be included are ‘premiumrate, sharedcost, tollfree, and voip.’ If you do not specify this value, the API takes it as a mobile phone type by default.
The second optional parameter is country_code that you need to write in two-letter ISO format. For example, US, RU, and LK. The API automatically infers the country code from your IP address if you do not include a value for this parameter. The following image shows an example response you will get by calling this endpoint. The response contains phone type, country code, prefix, and international and local numbers of the example phone number it returns. The ‘e164’ value indicates the phone number in standard E164 format with a plus sign.
/verify
You can use this endpoint for global phone number verification. For that, you have to specify the phone number in its mandatory ‘phone’ parameter. You can also specify the default country code as an optional parameter. The response contains the validity of the provided phone number and additional helpful information about it such as phone region, country, country code, country prefix, international, local, and E164 numbers, and the carrier. The following image shows an example response you will get when this endpoint is called.
Integrating the Veriphone API to an Application
This section will show how to integrate the Veriphone API into Python, PHP, Ruby, and Javascript software applications with sample code snippets. For this instance, we will be using the “GET /verify” endpoint for all the code snippets. In each code snippet, you need to include the ‘X-RapidAPI-key and X-RapidAPI-host parameters in the header, which you can obtain from the API page.
Python (requests)
The following Python code uses the “requests” library to send a GET request to the endpoint. Hence, first, you need to install the module on your computer. All the parameters are specified in the “querystring” variable. The request method of the Request object sends the API call. You can also use requests. Post method for this purpose.
import requests url = "https://veriphone.p.rapidapi.com/verify" querystring = {"phone":"+4915123577723"} headers = { 'x-rapidapi-key': "cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5", 'x-rapidapi-host': "veriphone.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
PHP (HTTP v2)
We use HTTP v2 for a PHP application. First, you need to create a client and a request class object. Then you need to set the API URL and the request method separately to the request object. Next, create a new QueryString object including all the parameters and set it to the request. Finally, send the request through the send method of the client object. You can also use cURL, HTTP V1, and Unirest/Request code snippets provided on the API website.
<?php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://veriphone.p.rapidapi.com/verify'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString([ 'phone' => '+4915123577723' ])); $request->setHeaders([ 'x-rapidapi-key' => 'cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5', 'x-rapidapi-host' => 'veriphone.p.rapidapi.com' ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
Ruby (net::http)
Suppose you use the net::http module in Ruby, import ‘openssl’ and ‘uri’ modules at the beginning. In this instance, bypass SSL certification verification setting it to ‘VERIFY_NONE.’ Unlike in the above code examples, you can directly set the parameters in the query string along with the URL.
require 'uri' require 'net/http' require 'openssl' url = URI("https://veriphone.p.rapidapi.com/verify?phone=%2B4915123577723") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5' request["x-rapidapi-host"] = 'veriphone.p.rapidapi.com' response = http.request(request) puts response.read_body
Javascript (Axios)
Integrating this API into a Javascript application is relatively easy. The following code snippet shows how to call this API using its ‘axios’ module. You can define the parameters, url, headers, and the request method in one Javascript object and use axios.request method to send the request and retrieve the response.
import axios from "axios"; const options = { method: 'GET', url: 'https://veriphone.p.rapidapi.com/verify', params: {phone: '+4915123577723'}, headers: { 'x-rapidapi-key': 'cJvLRNK0GfdM9WSMbQe3inU7REn8JVy5', 'x-rapidapi-host': 'veriphone.p.rapidapi.com' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); });
Alternatives to the Veriphone API
This API belongs to the Phone validation APIs category. Following are the similar Phone validation APIs available on the RapidAPI site.
Phone validation – Simple API can validate a phone number and provide information like the national and international phone number, country code, and if the phone is blacklisted.
Phone Number Validation – From this API, you can retrieve the phone number in global and E164 formats and its line type based on the provided country code.
Phone Number Verification – This API provides information about a phone number such as its validity, location, carrier, and different formats of the phone number, including E164 and RFC3966 formats
International Phone Number Validation– When you provide a phone number and its country code, this API returns the phone number of various ISO standard formats and its phone type
Phone Number Processor and Validator– A freemium API that does phone number validation and extracting information. All you have to provide for this API is a phone number and its country code.
Benefits of the Veriphone API
Easy to Integrate
Veriphone API requires only a few parameters with the request. Because of that, you do not have to spend a lot of time writing complicated code. Besides, you can find example code snippets in many programming languages with two or more frameworks or modules. Because of this simplicity, even someone with little to no background using APIs can master the API reasonably quickly.
Multiple Information
Apart from the validity of a given phone number, it provides other helpful information related to that phone number. Therefore, not only for phone validation, but you can also use the API for several functionalities like identifying different formats, phone types, network or carrier, etc. Because of the valuable information it provides, building a phone number validation tool is a much easier experience.
Freemium API
Veriphone API is a simple API that costs you only $200 per month to get its full capabilities. It also allows developers to get its full capabilities free of charge. It will be a huge benefit, particularly for students who learn about APIs and application developers to build innovative applications.
Summary
Veriphone API is a simple yet powerful phone validation API that you can use to build phone validation functions for your website. From this article, we discussed in detail its available endpoints, benefits, who can use this, and provided sample code snippets in Python, PHP, Ruby, and Javascript to show how to use this API in an application.
Leave a Reply