Build the future of communications.
Start building for free

Who's Calling? How to Identify a Phone Number Carrier with Twilio Lookup

blur-call-calling-1251088.jpg

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.

Lookup a carrier with Twilio

To lookup 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 carriers returned accurate?

Have you ever gotten a call from a weirdly invalid number or even from your own 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 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.

After looking up 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.

Authors
Sign up and start building
Not ready yet? Talk to an expert.