Skip to content

Instantly share code, notes, and snippets.

@deadflowers
Last active July 4, 2025 09:43
Show Gist options
  • Select an option

  • Save deadflowers/f753dd8d5ba3f3d10fb7a4fd4a43677d to your computer and use it in GitHub Desktop.

Select an option

Save deadflowers/f753dd8d5ba3f3d10fb7a4fd4a43677d to your computer and use it in GitHub Desktop.
Twilio Lookup API - Line Intelligence

linelookup.sh

Query the Twilio Lookup API to retrieve line type intelligence (mobile, landline, VoIP, etc.) for a given phone number.

🔧 Requirements

  • Bash

  • jq installed (for JSON formatting)

  • Twilio account with:

    • TWILIO_ACCOUNT_SID

    • TWILIO_AUTH_TOKEN

📦 Setup

Export your Twilio credentials in your shell:

export TWILIO_ACCOUNT_SID=your_account_sid 
export TWILIO_AUTH_TOKEN=your_auth_token

▶️ Usage

./linelookup.sh <10 Digit Phone Number>

This will return JSON output from Twilio with line type details.

📁 Output Example

{   "caller_name": null,   "country_code": "US",   "phone_number": "+17144780056",   "national_format": "(714) 478-0056",   "line_type_intelligence": {     "type": "mobile",     "carrier": "Verizon Wireless"   } }

Ray Kooyenga

#!/bin/bash
# Query Twilio Lookup API - line intelligence
# usage: linelookup.sh 7141234567
# ray kooyenga
# dependencies: jq for JSON, TWilio account with SID and Auth Token
lookup_phone_number() {
local phone_number="$1"
if [[ -z "$phone_number" ]]; then
echo "Error: Please provide a phone number in the format 7141234567"
exit 1
fi
# Be sure to set TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in environment
if [[ -z "$TWILIO_ACCOUNT_SID" || -z "$TWILIO_AUTH_TOKEN" ]]; then
echo "Error: TWILIO_ACCOUNT_SID or TWILIO_AUTH_TOKEN environment variables are not set."
exit 1
fi
# GET request to the Twilio Lookup API
curl -X GET "https://lookups.twilio.com/v2/PhoneNumbers/$phone_number?Fields=line_type_intelligence" \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \
| jq .
}
# Check if a phone number is passed as an argument
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <PhoneNumber>"
echo "Example: $0 7141234567"
exit 1
fi
lookup_phone_number "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment