Number Insight Basic
Use the Vonage Number Insight Basic API to determine:
- The country where a number is registered
- The local and international representation of that number
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:
`Key | Description |
---|---|
VONAGE_API_KEY |
Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET |
Your Vonage API secret (also available on your dashboard). |
INSIGHT_NUMBER |
The number you want to retrieve insight information for. |
.
Write the code
Add the following to ni-basic.sh
:
curl "https://api.nexmo.com/ni/basic/json?api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET&number=$INSIGHT_NUMBER"
Run your code
Save this file to your machine and run it:
sh ni-basic.sh
Prerequisites
npm install @vonage/server-sdk
Create a file named ni-basic.js
and add the following code:
const Vonage = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET
});
Write the code
Add the following to ni-basic.js
:
vonage.numberInsight.get({level: 'basic', number: INSIGHT_NUMBER}, (error, result) => {
if(error) {
console.error(error);
}
else {
console.log(result);
}
});
Run your code
Save this file to your machine and run it:
node ni-basic.js
Prerequisites
Add the following to `build.gradle`:
compile 'com.vonage:client:6.2.0'
Create a class named BasicInsight
and add the following code to the main
method:
VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();
Write the code
Add the following to the main
method of the BasicInsight
class:
BasicInsightResponse response = client.getInsightClient().getBasicNumberInsight(INSIGHT_NUMBER);
System.out.println("International format: " + response.getInternationalFormatNumber());
System.out.println("National format: " + response.getNationalFormatNumber());
System.out.println("Country: " + response.getCountryName() + " (" + response.getCountryCodeIso3() + ", +"
+ response.getCountryPrefix() + ")");
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.vonage.quickstart.insight
with the package containing BasicInsight
:
gradle run -Pmain=com.vonage.quickstart.insight.BasicInsight
Prerequisites
Install-Package Vonage
Create a file named BasicInsights.cs
and add the following code:
using Vonage;
using Vonage.NumberInsights;
using Vonage.Request;
Add the following to BasicInsights.cs
:
var creds = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret);
Write the code
Add the following to BasicInsights.cs
:
var request = new BasicNumberInsightRequest() { Number = insightNumber };
Prerequisites
composer require vonage/client
Write the code
Add the following to basic.php
:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);
$insights = $client->insights()->basic(INSIGHT_NUMBER);
Run your code
Save this file to your machine and run it:
php basic.php
Prerequisites
pip install vonage pprint
Write the code
Add the following to ni-basic.py
:
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
insight_json = client.number_insight.get_basic_number_insight(number=INSIGHT_NUMBER)
pprint(insight_json)
Run your code
Save this file to your machine and run it:
python ni-basic.py
Prerequisites
gem install vonage
Create a file named ni-basic.rb
and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)
Write the code
Add the following to ni-basic.rb
:
insight = client.number_insight.basic(
number: INSIGHT_NUMBER
)
puts insight.inspect
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"
}
For a description of each returned field and to see all possible values, see the Number Insights API documentation