WhatsApp Phone Numbers Bulk Validation Tutorial

July 15, 2024

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 response = Unirest.post("https://api.wassenger.com/v1/numbers/validate") .header("Content-Type", "application/json") .header("Token", "$API_KEY") .body("{\"country\":\"US\", \"numbers\":[{\"phone\":\"202-456-1414\"}, {\"phone\":\"+1 202 456 1414\"}, {\"phone\":\"1 415(858-6273)\"}]}") .asString(); ``` > 🤩 🤖 [**Wassenger**](https://wassenger.com/) is a complete communication platform and API solution for WhatsApp. [**Explore more than 100+ API use cases and automate anything on WhatsApp**](https://wassenger.com/) by signing up [for a free trial and getting started in minutes**!**](https://wassenger.com/register) #### Live testing the file upload using the API ![](/images/blog/whatsapp-phone-numbers-bulk-validation-tuto-02.png) [Explore our API live tester](https://app.wassenger.com/help/api-tester) ### FAQs #### Do I need a WhatsApp Business account? Our system works the same whether you have a Personal or a Business WhatsApp account. #### Can I use Wassenger for chatbots? Yes, you can build your chatbot with our API and webhooks. To do so, you need to subscribe to any Platform plan allowing you to implement chatbots on top of the API. Explore more from our related article [**here**](https://medium.com/@wassenger/build-a-whatsapp-chatgpt-powered-ai-chatbot-for-your-business-595a60eb17da). #### From where can I obtain the API code examples? Please check the [API documentation](https://app.wassenger.com/docs) and select the ready-to-use code example in the desired language. We provide code examples for most common languages and CLI tools, such as JavaScript, Node.js, Python, Ruby, PHP, Java, C#, Swift, Go and more. > ***Looking for more answers?*** [***Check out the extended FAQs***](https://app.wassenger.com/help/category/faq)***.*** #### Further useful resources #### API Documentation 🖥️ For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages: [https://app.wassenger.com/docs/#tag/Numbers/operation/validateNumbers](https://app.wassenger.com/docs/#tag/Numbers/operation/validateNumbers)

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free