Number Insight Advanced Webhook
Effective February 4, 2027, Vonage will sunset Vonage Number Insights. To ensure uninterrupted support and to provide a more scalable and future-proof solution, we encourage you to migrate to our enhanced offering: Vonage Identity Insights API. The Vonage Identity Insights API consolidates multiple phone number-related datasets into a single, flexible API, allowing you to request real-time information about a phone number and retrieve any combination of insights - such as number formatting, carrier details, SIM Swap and Subscriber Match - in one call.
Please review the Number Insights Transition Guide, which provides detailed guidance on API differences, required changes, and best practices for a smooth transition.
This code snippet shows you how to code the webhook handler that receives the data returned by an asynchronous call to the Number Insight Advanced API. See the Number Insight Advanced code snippet to learn how to code the initial request for the insight data.
Before attempting to run the code examples, replace the variable placeholders:
| キー | 説明 |
|---|---|
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. |
Prerequisites
Create a file named ni-advanced-async.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-advanced-async.js:
vonage.numberInsight.asyncAdvancedLookup(
INSIGHT_NUMBER,
INSIGHT_CALLBACK_URL,
)
.then((result) => console.log(result))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Write the code
Add the following to the main method of the AdvancedInsightWebhook class:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.numberinsight with the package containing AdvancedInsightWebhook:
Prerequisites
Add the following to build.gradle:
Write the code
Add the following to the main method of the AsyncInsightTrigger class:
port(3000);
Spark.post("/webhooks/insight", (req, res) -> {
AdvancedInsightResponse response = Jsonable.fromJson(req.body());
System.out.println("Country: " + response.getCountryName());
res.status(204);
return "";
});Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.insight with the package containing AsyncInsightTrigger:
Prerequisites
Create a file named NumberInsightsController.cs and add the following code:
Prerequisites
Write the code
Add the following to index.php:
$handler = function (Request $request, Response $response) {
$params = $request->getParsedBody();
error_log($params['status_message']);
error_log($params['country_code']);
error_log($params['current_carrier']['name']);
return $response->withStatus(204);
};Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
Prerequisites
Run your code
Save this file to your machine and run it:
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