Number Insight Advanced

The Number Insight Advanced API provides all the data from the Number Insight Standard API together with the following additional information:

  • If the number is likely to be valid
  • If the number is ported
  • If the number is reachable (not available in the US)
  • If the number is roaming and, if so, the carrier and country

Use this information to determine the risk associated with a number.

Note that the Advanced API does not provide any extra information about landlines than the Number Insight Standard API. For insights about landline numbers, use the Standard API.

This code snippet shows you how to trigger an asynchronous call to the Number Insight API. This is the approach Nexmo recommends. You can optionally use the Number Insight Advanced API synchronously, but be aware that synchronous use can result in timeouts.

Before attempting to run the code examples, replace the variable placeholders as instructed in replaceable variables.

Write the code

Add the following to ni-advanced-async.sh:

Copy to Clipboard
curl "https://api.nexmo.com/ni/advanced/async/json?api_key=$NEXMO_API_KEY&api_secret=$NEXMO_API_SECRET&number=$INSIGHT_NUMBER&callback=$WEBHOOK_URL"

View full source

Run your code

Save this file to your machine and run it:

sh ni-advanced-async.sh

Prerequisites

Install dependencies

npm install nexmo express body-parser

Write the code

Add the following to ni-advanced-async-client.js:

Copy to Clipboard
const Nexmo = require('nexmo');

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
});

nexmo.numberInsight.get({
  level: 'advancedAsync',
  number: INSIGHT_NUMBER,
  callback: 'https://demo.ngrok.io/webhooks/insight'
}, (error, result) => {
  if (error) {
    console.error(error);
  }
  else {
    console.log(result);
  }
});

View full source

Run your code

Save this file to your machine and run it:

node ni-advanced-async-client.js

Prerequisites

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:5.1.0'
Initialize your dependencies

Create a class named AdvancedInsightAsync and add the following code to the main method:

Copy to Clipboard
NexmoClient client = NexmoClient.builder()
        .apiKey(NEXMO_API_KEY)
        .apiSecret(NEXMO_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the AdvancedInsightAsync class:

Copy to Clipboard
InsightClient insightClient = client.getInsightClient();

AdvancedInsightRequest request = AdvancedInsightRequest.builder(INSIGHT_NUMBER)
        .async(true)
        .callback(ASYNC_CALLBACK_URL)
        .build();
insightClient.getAdvancedNumberInsight(request);

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.nexmo.quickstart.insight with the package containing AdvancedInsightAsync:

gradle run -Pmain=com.nexmo.quickstart.insight.AdvancedInsightAsync

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named ni-advanced-async-client.rb and add the following code:

Copy to Clipboard
client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET
)

View full source

Write the code

Add the following to ni-advanced-async-client.rb:

Copy to Clipboard
insight = client.number_insight.advanced(
  number: INSIGHT_NUMBER,
  callback: 'https//demo.ngrok.io/webhooks/insight'
)

puts insight.inspect

View full source

Run your code

Save this file to your machine and run it:

ruby ni-advanced-async-client.rb

The API acknowledges the request by returning the following information to the client:

{
    "request_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
    "number": "447700900000",
    "remaining_balance": "10.000000",
    "request_price": "0.03000000",
    "status": 0
}

When the data becomes available, it is sent to the specified webhook via a POST request. See the Number Insight Advanced Async Callback code snippet to learn how to code the webhook handler.