Number Insight Advanced (Síncrono)

A partir de 4 de fevereiro de 2027, a Vonage encerrará o serviço Vonage Number Insights. Para garantir um suporte ininterrupto e oferecer uma solução mais escalável e preparada para o futuro, recomendamos que você migre para nossa oferta aprimorada: API do Vonage Identity Insights. A Number Insight API consolida vários conjuntos de dados relacionados a números de telefone em uma única API flexível, permitindo que você solicite informações em tempo real sobre um número de telefone e obtenha qualquer combinação de informações — como formatação do número, detalhes da operadora, troca de SIM e correspondência de assinante — em uma única chamada.

Por favor, verifique o Guia de Transição do Numbers Insights, que oferece orientações detalhadas sobre as diferenças nas APIs, as alterações necessárias e as melhores práticas para uma transição tranquila.

Este trecho de código mostra como usar a Number Insight API de forma síncrona.

Nota: A Vonage não recomenda essa abordagem, pois ela pode resultar em tempo limite esgotado. Na maioria dos casos, você deve usar um chamada assíncrona à Number Insight API.

Antes de tentar executar os exemplos de código, substitua os marcadores de variáveis:

ChaveDescrição
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.

REAL_TIME_DATA

An optional flag to determine if you want real time data back in the response.

Escreva o código

Adicione o seguinte ao arquivo ` ni-advanced.sh`:

source "../config.sh"

curl \
  -u "${VONAGE_API_KEY}:${VONAGE_API_SECRET}" \
  "https://api.nexmo.com/ni/advanced/json?number=$INSIGHT_NUMBER"

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

sh ni-advanced.sh

Pré-requisitos

npm install @vonage/server-sdk

Crie um arquivo chamado ` ni-advanced.js ` e insira o seguinte código:

const { Vonage } = require('@vonage/server-sdk');

const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET,
});

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao arquivo ` ni-advanced.js`:

vonage.numberInsights.advancedLookup(INSIGHT_NUMBER)
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

node ni-advanced.js

Pré-requisitos

Adicione o seguinte ao arquivo ` build.gradle`:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

Crie um arquivo chamado ` AdvancedInsightSync ` e adicione o código a seguir ao método ` main `:

val client = Vonage {
    apiKey(VONAGE_API_KEY)
    apiSecret(VONAGE_API_SECRET)
}

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao método ` main ` do arquivo ` AdvancedInsightSync `:

val response = client.numberInsight.advanced(INSIGHT_NUMBER, INSIGHT_CALLBACK_URL)
println(response)

Ver código-fonte completo

Execute seu código

Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:

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

Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.kt.numberinsight ` pelo pacote que contém ` AdvancedInsightSync`:

gradle run -Pmain=com.vonage.quickstart.kt.numberinsight.AdvancedInsightSync

Pré-requisitos

Adicione o seguinte ao arquivo ` build.gradle`:

implementation 'com.vonage:server-sdk:9.3.1'

Crie um arquivo chamado ` AdvancedInsight ` e adicione o código a seguir ao método ` main `:

VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao método ` main ` do arquivo ` AdvancedInsight `:

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() == RoamingStatus.ROAMING) {
        System.out.print("    Currently roaming in: " + roaming.getRoamingCountryCode());
        System.out.println(" on the network " + roaming.getRoamingNetworkName());
    }
}

Ver código-fonte completo

Execute seu código

Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:

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

Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.insight ` pelo pacote que contém ` AdvancedInsight`:

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

Pré-requisitos

Install-Package Vonage

Crie um arquivo chamado ` AdvancedSync.cs ` e insira o seguinte código:

using Vonage;
using Vonage.NumberInsights;
using Vonage.Request;

Ver código-fonte completo

Adicione o seguinte ao arquivo ` AdvancedSync.cs`:


var creds = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao arquivo ` AdvancedSync.cs`:


var request = new AdvancedNumberInsightRequest() { Number = INSIGHT_NUMBER};

Ver código-fonte completo

Pré-requisitos

composer require vonage/client

Escreva o código

Adicione o seguinte ao arquivo ` advanced.php`:

$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

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

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

php advanced.php

Pré-requisitos

pip install vonage python-dotenv

Escreva o código

Adicione o seguinte ao arquivo ` ni-advanced.py`:

from vonage import Auth, Vonage
from vonage_number_insight import (AdvancedSyncInsightRequest,
                                   AdvancedSyncInsightResponse)

client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))

insight: AdvancedSyncInsightResponse = client.number_insight.get_advanced_info_sync(
    AdvancedSyncInsightRequest(number=INSIGHT_NUMBER)
)
pprint(insight)

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

python number-insight/ni-advanced.py

Pré-requisitos

gem install vonage

Crie um arquivo chamado ` ni-advanced.rb ` e insira o seguinte código:

client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

Ver código-fonte completo

Escreva o código

Adicione o seguinte ao arquivo ` ni-advanced.rb`:

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

puts insight.inspect

Ver código-fonte completo

Execute seu código

Salve este arquivo no seu computador e execute-o:

ruby ni-advanced.rb

A resposta da API contém os seguintes dados:

{
    "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" },
    "real_time_data": {
     "active_status": "active",
     "handset_status": "on"
    }
}

Para obter uma descrição de cada campo retornado e ver todos os valores possíveis, consulte o Documentação da Number Insight API