Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Lookup v2 Quickstart


The Lookup API allows you to query information on a phone number so that you can make a trusted interaction with your user. With Lookup, you can format and validate phone numbers with the free Basic Lookup request to increase deliverability and get detailed information on a number's carrier and caller by adding on optional data packages. See Lookup v2 API Reference for more details on Lookup's capabilities.

In this Quickstart we will explore how to get started with Lookup and learn how to make these requests:


Setup: Authentication

setup-authentication page anchor

New to Twilio? You'll want to start by creating a Twilio Account(link takes you to an external page).

Next, login to Twilio Console(link takes you to an external page) and note your Account SID and Auth Token. You'll need these to authenticate your Lookup requests with HTTP Basic authentication(link takes you to an external page), using your Account SID as the username and your Auth Token as the password.


All Lookup requests begin with an HTTP GET request to this base URL:


_10
https://lookups.twilio.com/v2/PhoneNumbers/{PhoneNumber}

The Twilio REST API is served over HTTPS. To ensure data privacy, unencrypted HTTP is not supported.

{PhoneNumber} is the only required parameter and represents the phone number you are querying in E.164 or national format. If the phone number is provided in national format, please also specify the country in the optional parameter CountryCode. Otherwise, CountryCode will default to US.


A Basic Lookup returns the provided phone number in E.164 and national formats and validates the phone number. Note that this is a free feature.

Let's try it out by making this cURL request in our terminal, replacing the PhoneNumber, YOUR_ACCOUNT_SID, and YOUR_AUTH_TOKEN variables with your own data:


_10
curl -X GET "https://lookups.twilio.com/v2/PhoneNumbers/{PhoneNumber}" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

You should see a response similar to this one:


_15
{
_15
"calling_country_code": "1",
_15
"country_code": "US",
_15
"phone_number": "+14159929960",
_15
"national_format": "(415) 992-9960",
_15
"valid": true,
_15
"validation_errors": null,
_15
"caller_name": null,
_15
"sim_swap": null,
_15
"call_forwarding": null,
_15
"live_activity": null,
_15
"line_type_intelligence": null,
_15
"identity_match": null,
_15
"url": "https://lookups.twilio.com/v2/PhoneNumbers/+14159929960"
_15
}

The fields calling_country_code, country_code, phone_number, and national_format provide formatting information and the valid field indicates if the phone number could be a valid assigned number.

See this example below for how you can use a Twilio Helper Library in your preferred language to perform the same request.

Basic Lookup

basic-lookup page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.lookups.v2.phoneNumbers('+14159929960')
_10
.fetch()
_10
.then(phone_number => console.log(phone_number.phoneNumber));

Output

_19
{
_19
"calling_country_code": "1",
_19
"country_code": "US",
_19
"phone_number": "+14159929960",
_19
"national_format": "(415) 992-9960",
_19
"valid": true,
_19
"validation_errors": null,
_19
"caller_name": null,
_19
"sim_swap": null,
_19
"call_forwarding": null,
_19
"line_status": null,
_19
"line_type_intelligence": null,
_19
"identity_match": null,
_19
"reassigned_number": null,
_19
"sms_pumping_risk": null,
_19
"phone_number_quality_score": null,
_19
"pre_fill": null,
_19
"url": "https://lookups.twilio.com/v2/PhoneNumbers/+14159929960"
_19
}


Introducing Lookup's data packages

introducing-lookups-data-packages page anchor

Lookup supports a number of data packages that allow you to query for additional carrier and caller information relating to a phone number. See Lookup v2 API Reference for a full list of available packages and how to onboard to each one.

In this Quickstart, we'll explain how to use the Line Type Intelligence package.

Perform a Line Type Intelligence Lookup

perform-a-line-type-intelligence-lookup page anchor

The Line Type Intelligence package allows you to get the line type of a phone number including mobile, landline, fixed VoIP, non-fixed VoIP, toll-free, and more. Note that this is a paid feature.

The video below shows how to check a phone number's line type with Lookup using Node.js and the Twilio Node Helper Library.

To make a Line Type Intelligence request, build on the API base URL by adding the Fields parameter with the value line_type_intelligence.

Make the following cURL request in the terminal, replacing the PhoneNumber, YOUR_ACCOUNT_SID, and YOUR_AUTH_TOKEN variables with your own data:


_10
curl -X GET "https://lookups.twilio.com/v2/PhoneNumbers/{PhoneNumber}?Fields=line_type_intelligence" \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Let's check the response:


_22
{
_22
"calling_country_code": "1",
_22
"country_code": "US",
_22
"phone_number": "+14159929960",
_22
"national_format": "(415) 992-9960",
_22
"valid": true,
_22
"validation_errors": null,
_22
"caller_name": null,
_22
"sim_swap": null,
_22
"call_forwarding": null,
_22
"live_activity": null,
_22
"line_type_intelligence":
_22
{
_22
"error_code": null,
_22
"mobile_country_code": "240",
_22
"mobile_network_code": "38",
_22
"carrier_name": "Twilio - SMS/MMS-SVR",
_22
"type": "nonFixedVoip"
_22
},
_22
"identity_match": null,
_22
"url": "https://lookups.twilio.com/v2/PhoneNumbers/+14159929960"
_22
}

All of the fields we saw in the previous Basic Lookup request are present along with new information included in the line_type_intelligence object.

Line Type Intelligence Lookup

line-type-intelligence-lookup page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.lookups.v2.phoneNumbers('+14159929960')
_10
.fetch({fields: 'line_type_intelligence'})
_10
.then(phone_number => console.log(phone_number.lineTypeIntelligence));

Output

_25
{
_25
"calling_country_code": "1",
_25
"country_code": "US",
_25
"phone_number": "+14159929960",
_25
"national_format": "(415) 992-9960",
_25
"valid": true,
_25
"validation_errors": null,
_25
"caller_name": null,
_25
"sim_swap": null,
_25
"call_forwarding": null,
_25
"line_status": null,
_25
"line_type_intelligence": {
_25
"error_code": null,
_25
"mobile_country_code": "240",
_25
"mobile_network_code": "38",
_25
"carrier_name": "Twilio - SMS/MMS-SVR",
_25
"type": "nonFixedVoip"
_25
},
_25
"identity_match": null,
_25
"reassigned_number": null,
_25
"sms_pumping_risk": null,
_25
"phone_number_quality_score": null,
_25
"pre_fill": null,
_25
"url": "https://lookups.twilio.com/v2/PhoneNumbers/+14159929960"
_25
}


Rate this page: