Menu

Expand
Rate 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 to increase deliverability and get detailed information on a number's carrier and caller. 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:

  • Formatting and Validation Lookup: Returns the phone number in E.164 and national formats and performs basic phone number validation. This is a free feature.
  • Line Type Intelligence Lookup: Returns the line type of a phone number including mobile, landline, fixed VoIP, non-fixed VoIP, toll-free, and more. This is a paid feature, learn more about Lookup pricing here.

Setup: Authentication

New to Twilio? You’ll want to start by creating a Twilio Account.

Next, login to Twilio Console and note your Account SID and Auth Token. You’ll need these to authenticate your Lookup requests with HTTP Basic authentication, using your Account SID as the username and your Auth Token as the password.

Setup: Base API URL

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

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.

Perform a Formatting and Validation Lookup

A Formatting and Validation 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:

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

You should see a response similar to this one:

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

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.

        
        
        

        Formatting and Validation Lookup

        Introducing Lookup's data packages

        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

        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.

        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:

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

        Let's check the response:

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

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

              
              
              

              Line Type Intelligence Lookup

              Rate this page:

              Need some help?

              We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

                    
                    
                    

                    Thank you for your feedback!

                    Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

                    Sending your feedback...
                    🎉 Thank you for your feedback!
                    Something went wrong. Please try again.

                    Thanks for your feedback!

                    thanks-feedback-gif