Number Insight Advanced

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

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.

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.sh:

Copy to Clipboard
source "../config.sh"

curl -X "POST" "https://api.nexmo.com/ni/advanced/json" \
     -d "api_key=$NEXMO_API_KEY" \
     -d "api_secret=$NEXMO_API_SECRET" \
     -d "number=$INSIGHT_NUMBER"

View full source 

Run your code

Save this file to your machine and run it:

$ sh ni-advanced.sh

Prerequisites

Install dependencies

$ npm install nexmo
Initialize your dependencies

Create a file named ni-advanced.js and add the following code:

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

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

View full source 

Write the code

Add the following to ni-advanced.js:

Copy to Clipboard
nexmo.numberInsight.get({level: 'advanced', number: INSIGHT_NUMBER}, (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.js

Prerequisites

Install dependencies

Add the following to build.gradle:

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

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

Copy to Clipboard
NexmoClient client = new 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 AdvancedInsight class:

Copy to Clipboard
AdvancedInsightResponse response = client.getInsightClient().getAdvancedNumberInsight(INSIGHT_NUMBER);

System.out.println("BASIC INFO:");
System.out.println("International format: " + response.getInternationalFormatNumber());
System.out.println("National format: " + response.getNationalFormatNumber());
System.out.println("Country: " + response.getCountryName() + " (" + response.getCountryCodeIso3() + ", +"
        + response.getCountryPrefix() + ")");
System.out.println();
System.out.println("STANDARD INFO:");
System.out.println("Current carrier: " + response.getCurrentCarrier().getName());
System.out.println("Original carrier: " + response.getOriginalCarrier().getName());

System.out.println();
System.out.println("ADVANCED INFO:");
System.out.println("Validity: " + response.getValidNumber());
System.out.println("Reachability: " + response.getReachability());
System.out.println("Ported status: " + response.getPorted());

RoamingDetails roaming = response.getRoaming();
if (roaming == null) {
    System.out.println("- No Roaming Info -");
} else {
    System.out.println("Roaming status: " + roaming.getStatus());
    if (response.getRoaming().getStatus() == RoamingDetails.RoamingStatus.ROAMING) {
        System.out.print("    Currently roaming in: " + roaming.getRoamingCountryCode());
        System.out.println(" on the network " + roaming.getRoamingNetworkName());
    }
}

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 AdvancedInsight:

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

Prerequisites

Install dependencies

$ Install-Package Nexmo.Csharp.Client
Initialize your dependencies

Create a file named NumberInsightController.cs and add the following code:

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

View full source 

Write the code

Add the following to NumberInsightController.cs:

Copy to Clipboard
var results = Client.NumberInsight.RequestAdvanced(new NumberInsight.NumberInsightRequest()
{
    Number = number,
});

View full source 

Run your code

Save this file to your machine and run it:

$ (Run using your IDE)

Prerequisites

Install dependencies

$ composer require nexmo/client

Write the code

Add the following to advanced.php:

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);

$insights = $client->insights()->advanced(INSIGHT_NUMBER);

View full source 

Run your code

Save this file to your machine and run it:

$ php advanced.php

Prerequisites

Install dependencies

$ pip install nexmo pprint

Write the code

Add the following to ni-advanced.py:

Copy to Clipboard
client = nexmo.Client(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)

insight_json = client.get_advanced_number_insight(number=INSIGHT_NUMBER)
pprint(insight_json)

View full source 

Run your code

Save this file to your machine and run it:

$ python ni-advanced.py

Prerequisites

Install dependencies

$ gem install nexmo

Write the code

Add the following to ni-advanced.rb:

Copy to Clipboard
require 'nexmo'

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

insight = client.number_insight.advanced(
  number: INSIGHT_NUMBER
)

puts insight.inspect

View full source 

Run your code

Save this file to your machine and run it:

$ ruby ni-advanced.rb

The response from the API contains the following data:

{
    "status": 0,
    "status_message": "Success",
    "lookup_outcome": 0,
    "lookup_outcome_message": "Success",
    "request_id": "75fa272e-4743-43f1-995e-a684901222d6",
    "international_format_number": "447700900000",
    "national_format_number": "07700 900000",
    "country_code": "GB",
    "country_code_iso3": "GBR",
    "country_name": "United Kingdom",
    "country_prefix": "44",
    "request_price": "0.03000000",
    "remaining_balance": "10.000000",
    "current_carrier": {
        "network_code": "23420",
        "name": "Hutchison 3G Ltd",
        "country": "GB",
        "network_type": "mobile"
    },
    "original_carrier": {
        "network_code": "23410",
        "name": "Telefonica UK Limited",
        "country": "GB",
        "network_type": "mobile"
    },
    "valid_number": "valid",
    "reachable": "reachable",
    "ported": "ported",
    "roaming": {"status": "not_roaming"}
}

For a description of each returned field and to see all possible values, see the Number Insights API documentation