Getting Started with Nexmo Number Insight APIs and ASP.NET
Published on May 12, 2021

Our Number Insight API is perfect for real-time validation of user input that could potentially protect your apps from fraud and spam and help you get details about a phone number such as validity, reachability and roaming status. You can use also the Number Insight API to validate that a phone number is formatted properly. This is very useful especially if you are using our other APIs.

Number insight is available with three levels:

  • Basic: used to format numbers and display them in international and local representations.

  • Standard: best used to identify number type to decide between SMS and Voice; block virtual numbers.

  • Advanced: best used to determine risk based on numbers.

The advanced API is also available asynchronously as well as synchronously.

You can check the full list of what's available on each level on the Number Insight documentation.

For the sake of readability and getting straight to the point, I'm going to post this tutorial as a series of step-by-step articles instead of one long post. In each article, we will see how to use one of the three levels of the Number Insight API with an ASP.NET app. So let's get started!

Prerequisites

  • Visual Studio 2017.

  • A project set up for this tutorial series which you can find on Github.

  • Optional: Nexmo CLI.

DT API Account

To complete this tutorial, you will need a DT 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 DT API Dashboard.

Configuration

We will be showcasing how to use Number Insight API with an ASP.NET Web Application. So the first step is to create an ASP.NET project.

  • Launch Visual Studio and create a new ASP.NET Web Application (.NET Framework) project.

ASP.NET GifASP.NET Gif

  • Select the MVC Template and ensure the Authentication type is set to No Authentication. Click OK to create the project

    MVC templateMVC template

  • Install the Nexmo C# Client Library via the NuGet Package Manager Console.

Install-Package Nexmo.Csharp.Client

Voila, we now have the template for the ASP.NET web app project and we are ready to write some code.

ASP.NET Project TemplateASP.NET Project Template

Getting some number insights

Now that we set up the project, let's see how to get some insights. Under the Controllers folder, create a new controller called NumberInsightController.cs. In the constructor, instantiate a Nexmo Client and authenticate with the API using your API key and secret. Those can be found on your Nexmo dashboard.

public Client Client { get; set; }

public NumberInsightController()
{
    Client = new Client(creds: new Nexmo.Api.Request.Credentials
    {
        ApiKey = "NEXMO_API_KEY",
        ApiSecret = "NEXMO_API_SECRET"
    });
}

Then under the views folder, create a new folder called NumberInsight. This folder will contain all Number Insight views we will need. We will need an Index.cshtml view to allow the navigation to the other views.

<div>
    <h1>Number Insight</h1>
    <hr style="height:2px;border:none;color:#333;background-color:black">
    <h2>@Html.ActionLink("Basic", "Basic", "NumberInsight")</h2>
    <h2>@Html.ActionLink("Standard", "Standard", "NumberInsight")</h2>
    <h2>@Html.ActionLink("Advanced", "Advanced", "NumberInsight")</h2>
</div>

Recap

In this first article of the guideline, we:

  • setup the ASP.NET project.

  • installed the Nexmo C# Client Library.

  • prepared the main skeleton of our project.

In the second article, we will learn how to get Basic Insights.

Rabeb OthmaniVonage Alumni

Rabeb was a Developer Advocate at Nexmo focusing on cloud communication APIs and helping developers get the best experience possible when building their apps. Other than writing code for a living, Rabeb advocates for bringing more women and minorities into tech, thus her involvement with Women Who Code and different tech communities. She leads the Women Who Code Network in Bristol.

Ready to start building?

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