Number Insight Basic

Use Nexmo's Number Insight Basic API to determine:

This can help you present numbers to your users in the correct format for their locale.

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

Write the code

Add the following to ni-basic.sh:

Copy to Clipboard
curl -X "POST" "https://api.nexmo.com/ni/basic/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-basic.sh

Prerequisites

Install dependencies

$ npm install nexmo
Initialize your dependencies

Create a file named ni-basic.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-basic.js:

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

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.RequestBasic(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 basic.php:

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

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

View full source 

Run your code

Save this file to your machine and run it:

$ php basic.php

Prerequisites

Install dependencies

$ pip install nexmo pprint

Write the code

Add the following to ni-basic.py:

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

insight_json = client.get_basic_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-basic.py

Prerequisites

Install dependencies

$ gem install nexmo

Write the code

Add the following to ni-basic.rb:

Copy to Clipboard
require 'nexmo'

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

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

puts insight.inspect

View full source 

Run your code

Save this file to your machine and run it:

$ ruby ni-basic.rb

The response from the API contains the following data:

{
    "status": 0,
    "status_message": "Success",
    "request_id": "fcb1e9a2-db9c-4ea2-84be-4e60da45e187",
    "international_format_number": "447700900000",
    "national_format_number": "07700 900000",
    "country_code": "GB",
    "country_code_iso3": "GBR",
    "country_name": "United Kingdom",
    "country_prefix": "44"
}