Three Levels of Phone Number Insights and Identification
最終更新日 November 7, 2024

Introduction

How much information can a phone number reveal? You're in the right place if you've heard of Vonage’s Number Insight API but need to know which version is best for your needs.

In this blog post, I'll show you how to use Number Insight API. We’ll output information about a phone number from basic to advanced so you can choose the right one for your project. We'll also build an app using Node.js and Express that allows users to input a phone number and retrieve details like carrier, country, and more.

The complete source code for this tutorial is available on GitHub.

Prerequisites

To follow along with this tutorial, you’ll need the following:

  • A Vonage Account

  • A text editor or IDE  like Visual Studio Code

  • Node and npm installed

Vonage API Account

To complete this tutorial, you will need a Vonage API account. If you don’t have one already, you can sign up today and start building with free credit. Once you have an account, you can find your API Key and API Secret at the top of the Vonage API Dashboard.

Application Overview

Phone Number Lookup interface displaying results in three sections: Basic, Standard, and Advanced Lookups. Each section contains blurred or obscured data, represented by asterisks or a blur effect, indicating sensitive information about the phone number. The page has a text input field at the top where users can enter a phone number for lookup, followed by a button labeled 'Lookup' to initiate the process. The results are displayed in three separate boxes with distinct pastel background colors for each lookup level: orange for Basic, green for Standard, and pink for Advanced.Phone Number LookupWe will build an Express.js app that takes a phone number as input and uses Vonage’s Number Insights API to perform three types of lookups: basic, standard, and advanced. Each lookup will return different levels of information about the number, which will be displayed in separate sections of the UI.

The application's flow is as follows: First, the user enters a phone number, which the app validates according to the E.164 National and International standard. The app performs basic, standard, and advanced lookups using Vonage’s API. The responses are displayed in the UI side by side to allow for immediate comparison.

Project Setup

The complete source code for this tutorial is available on GitHub. You can clone the project and install the dependencies.

npm install express @vonage/auth @vonage/number-insights dotenv

Add Your Environment Variables 

Create a .env file in your project root and add your Vonage API credentials. The GitHub project comes with a .env.example file, which you can copy and paste into your .env file and add your API credentials.

# .env
VONAGE_API_KEY=your_vonage_api_key
VONAGE_API_SECRET=your_vonage_api_secret

The VONAGE_API_KEY and VONAGE_API_SECRET can be found on the Vonage Dashboard. Michael's blog post explains how to use environment variables in Node.js.

Build the Server

In index.js,we set up the Express server with routes for performing basic, standard, and advanced lookups. The code sets an endpoint: /lookup that calls Vonage’s Number Insight API to retrieve different levels of information about a phone number.

Build the Front-End

Let’s build the UI in the index.js file. Here, we will add a form for the user to input a phone number, and three sections will display the results in different levels of detail.

Run the Application

To run the app, make sure your Express server is running. You can start it by running:

npm run dev

Then, open a browser and go to http://localhost:3000. Enter the phone number you want to check and click ‘Lookup.’ Three options will appear on demand: basic, standard, and advanced lookup responses.

NOTE: Don't use a leading + or 00 when entering a phone number. Start with the country code, for instance, 17700900000.

Conclusion

You have reached the end of this tutorial! Throughout this guide, we built a phone number lookup app using Vonage’s Number Insight API. This app allows users to perform basic, standard, and advanced lookups, providing valuable information about a phone number. The Vonage Number Insight API shows a number’s validity, reachability, and roaming status. It also tells you how to format the number correctly in your application.

Go ahead and expand on what you've learned today. Let us know what you build on our Vonage Community Slack, or message us on X!

Amanda CavallaroDeveloper Advocate

Ready to start building?

Experience seamless connectivity, real-time messaging, and crystal-clear voice and video calls-all at your fingertips.

Subscribe to Our Developer Newsletter

Subscribe to our monthly newsletter to receive our latest updates on tutorials, releases, and events. No spam.