Have you ever wanted to ensure your company’s client numbers are correctly saved on your contact list? Well, with Wassenger that is a game-changer for direct communication. For businesses, verifying the validity, digits and format of random and not normalised phone numbers to the international E164 format is essential to maximize marketing efforts, save time, and reduce costs when communicating with potential clients in today’s global-scale digital businesses.
Following this tutorial, you can clear and validate your database phone numbers using Wassenger’s API and get normalized, filtered, and valid phone numbers in an E164 format that you can use to make phone calls, send WhatsApp or SMS messages to your user base (by the way, Wassenger can help you better communicate on WhatsApp, learn more here)
Wassenger offers a dependable solution for validating phone numbers on WhatsApp, simplifying communication and enhancing customer engagement. In this article, we’ll delve into the significance of number validation and how Wassenger can assist in optimizing your outreach strategies.
🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes**!**
Requirements
- To have a WhatsApp number already linked to the platform and online.
- User API key token needs to be used on every API request that requires authentication
In this tutorial we will use the following API endpoint:
Breaking news! You can now validatie a list of numbers in a single API request by passing them in the body API call. Click here to test it
Validate the numbers
validate and normalize a list of phone numbers, optionally enforcing the country code or local prefix.
The validation is only performed at the digits format level, it does not validate if a given phone number exists on WhatsApp.
Target API URL (POST)
User API key token needs to be used on every API request that requires authentication
https://api.wassenger.com/v1/numbers/validate
Required HTTPS headers
You can define it via the “token” URL query param or the “Token” HTTP request header.
Content-Type: application/json
Token: $API-TOKEN
Request body in JSON format
{
"country": "US",
"numbers": [
{
"phone": "202-456-1414"
},
{
"phone": "+1 202 456 1414"
},
{
"phone": "1 415(858-6273)"
}
]
}
Get the API response
{
"numbers": [
{
"valid": true,
"error": null,
"phone": "+12024561414",
"wid": "12024561414@c.us",
"input": "202-456-1414",
"kind": "fixed_line",
"countryPrefix": 1,
"country": "US",
"formats": {
"local": "2024561414",
"national": "2024561414",
"international": "+12024561414"
}
}
],
"summary": {
"valid": 3,
"invalid": 0
}
}
Validate numbers using code
Explore how to use the code in your browser without installing any software.
Also, you can find different languages you can test on Replit.com:
# Examples requires to have installed requests Python package. # Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/numbers/validate"
payload = { "country": "US", "numbers": [{ "phone": "202-456-1414" }, { "phone": "+1 202 456 1414" }, { "phone": "1 415 (858-6273)" }] } headers = { "Content-Type": "application/json", "Token": "$API_KEY" }
response = requests.post(url, json=payload, headers=headers)
print(response.json())
"https://api.wassenger.com/v1/numbers/validate", CURLOPT\_RETURNTRANSFER => true, CURLOPT\_ENCODING => "", CURLOPT\_MAXREDIRS => 10, CURLOPT\_TIMEOUT => 30, CURLOPT\_HTTP\_VERSION => CURL\_HTTP\_VERSION\_1\_1, CURLOPT\_CUSTOMREQUEST => "POST", CURLOPT\_POSTFIELDS => json\_encode(\[ 'country' => 'US', 'numbers' => \[ \[ 'phone' => '202-456-1414' \], \[ 'phone' => '+1 202 456 1414' \], \[ 'phone' => '1 415 (858-6273)' \] \] \]), CURLOPT\_HTTPHEADER => \[ "Content-Type: application/json", "Token: $API\_KEY" \], \]); $response = curl\_exec($curl); $err = curl\_error($curl); curl\_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } - [PHP](https://replit.com/new) \# Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. \# Install it by running: pecl install pecl\_http \# More information: https://pecl.php.net/package/pecl\_http/3.2.0 append(json\_encode(\[ 'country' => 'US', 'numbers' => \[ \[ 'phone' => '202-456-1414' \], \[ 'phone' => '+1 202 456 1414' \], \[ 'phone' => '1 415 (858-6273)' \] \] \])); $request->setRequestUrl('https://api.wassenger.com/v1/numbers/validate'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => '$API\_KEY' \]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); - [Go](https://replit.com/new) ```swift package main import( "fmt" "strings" "net/http" "io" ) func main() { url:= "https://api.wassenger.com/v1/numbers/validate" payload:= strings.NewReader("{\"country\":\"US\", \"numbers\":[{\"phone\":\"202-456-1414\"}, {\"phone\":\"+1 202 456 1414\"}, {\"phone\":\"1 415(858-6273)\"}]}") req, _:= http.NewRequest("POST", url, payload) req.Header.Add("Content-Type", "application/json") req.Header.Add("Token", "$API_KEY") res, _:= http.DefaultClient.Do(req) defer res.Body.Close() body, _:= io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` - [C#](https://replit.com/new) (RestClient) ```swift // This code requires you to have installed RestSharp package. // Documentation: https://restsharp.dev // Installation: https://www.nuget.org/packages/RestSharp var client = new RestClient("https://api.wassenger.com/v1/numbers/validate"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Token", "$API_KEY"); request.AddParameter("application/json", "{\"country\":\"US\", \"numbers\":[{\"phone\":\"202-456-1414\"}, {\"phone\":\"+1 202 456 1414\"}, {\"phone\":\"1 415(858-6273)\"}]}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` - [Ruby](https://replit.com/new) require 'uri' require 'net/http' url = URI("https://api.wassenger.com/v1/numbers/validate") http = Net::HTTP.new(url.host, url.port) http.use\_ssl = true request = Net::HTTP::Post.new(url) request\["Content-Type"\] = 'application/json' request\["Token"\] = '$API\_KEY' request.body = "{\\"country\\":\\"US\\",\\"numbers\\":\[{\\"phone\\":\\"202-456-1414\\"},{\\"phone\\":\\"+1 202 456 1414\\"},{\\"phone\\":\\"1 415 (858-6273)\\"}\]}" response = http.request(request) puts response.read\_body - [Java](https://replit.com/new) ```swift // This code requires you to have installed Unirest package. // Documentation: https://kong.github.io/unirest-java/#requests // Installation: http://kong.github.io/unirest-java/ HttpResponse





