How to Identify a Phone Number Carrier with Twilio Lookup

April 10, 2019
Written by

We've all received spam phone calls from a number we don't recognize, and sometimes the scammers go as far as to leave cryptic voicemails or text messages. Some bad actors use phone numbers from free online providers to create fake profiles to scam or spam. Twilio's Carrier Lookup API helps you identify the carrier behind the phone number to learn which users have real mobile numbers.

Identify a phone number carrier With Twilio

To identify a phone number you will need:

You can query the Twilio Lookup API for information about a phone number. There are two Types  of requests the API can perform: carrier and caller-name. This example focuses on carrier.

The following request will return carrier information about a phone number. The phone number in the request URL must be in E.164 format like +18557477626. Replace the credentials with your Account SID and Auth Token found in the console.

In your terminal, run the following code:

curl -X GET \
'https://lookups.twilio.com/v1/PhoneNumbers/+18557477626?Type=carrier' \
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token

If you want to add this functionality in an application, Twilio has helper libraries in languages including C#, Ruby, Python, Java, JavaScript, and PHP. This will return a JSON response:


{
    "caller_name": null,
    "country_code": "US",
    "phone_number": "+18557477626",
    "national_format": "(855) 747-7626",
    "carrier": {
        "mobile_country_code": null,
        "mobile_network_code": null,
        "name": "Twilio - Toll-Free - SMS-Sybase365/MMS-SVR",
        "type": "voip",
        "error_code": null
    },
    "add_ons": null,
    "url": "https://lookups.twilio.com/v1/PhoneNumbers/+18557477626?Type=carrier"
}

You can see that the carrier name for our example number, 1 (855) 747-7626, is Twilio. Similar information is returned for mobile and landline carriers such as AT&T or Level 3 Communications.

Try running the request again with your own phone number and see what comes back! Bear in mind that carriers rebrand themselves constantly and that the names used for carriers likely will change over time.

Are the carrier lookups accurate?

identify a phone number

404 not found response from Lookup API

Have you ever gotten a call from a weirdly invalid number or even from your own cell phone number? I got a call from this 9-digit invalid number earlier today -- that can't be right! The way telephony systems are set up today, anyone can spoof a call or a text message from any number. Even if they don’t own that number.

Twilio doesn't allow customers to use numbers that they don't own. This practice, unfortunately, doesn’t prevent others from spoofing Twilio serviced numbers. This isn't cool so we're working with other industry leaders to address spoofing. Although we’re optimistic these efforts will have a big impact, we don’t expect them to start paying off until 2020.

What about a Reverse Phone Lookup?

Reverse phone lookup is used for telephone number identification. You type in a number into a search engine or service like White Pages to learn more about the person calling or texting you. If the number is from a landline, this can be very useful, providing information like the caller's address and name or details about a business.

However, if you type in a mobile number, you probably won't find any information other than the location associated with the area code (unless you're willing to pay to access the data). This is where using Twilio Lookup to find out which carrier owns the phone number and find out if the call is spam, really comes in handy!

After identifying carrier information, what's next?

We know we're not the only ones who are curious who's calling, so we built a public Twilio bot that uses the Lookup API to let you know a number's carrier. 

Text +1 (855) 747-7626* with a phone number to check if it is from Twilio. That’s +1 (855) 747-ROBO

*standard text messaging rates may apply

If you're getting spam calls or texts from a Twilio number, this text hotline will help you report it. Learn more about this and what we're doing to stop spam on our platform.

Here are some other things you can build with the Lookup API:

For more information, check out the Lookup API documentation. Have you built something that takes advantage of Twilio Lookup? Let me know in the comments or on Twitter @kelleyrobinson.