Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.leadx.com/llms.txt

Use this file to discover all available pages before exploring further.

You’re a sales rep who has a list of prospects’ LinkedIn profiles. Before you perform any additional outreach, you want to enrich these leads with:
  • Mobile number
  • Verified company info
We’ll write a script that takes a CSV-style input (in this example, inline for simplicity) and produces a new CSV with enriched lead data.

Prerequisites

Before you begin, ensure you have the following:
  • A valid LeadX API Key
  • Python 3.7+ installed on your machine
  • The requests library installed (install it using pip install requests)

Enrich Prospect Data

1

Start with a LinkedIn URL

Let’s say you’ve got nothing more than a CSV file of LinkedIn profiles for your prospects. With the /mobile-numbers/enrich endpoint, you can turn that single URL into a direct phone number you can use for outreach. The first function takes in a LinkedIn profile and returns the associated mobile number.
enrich-leads.py
import os, requests, csv
API_KEY = os.getenv("LEADX_API_KEY")
BASE_URL = "https://api.leadx.com/v1"
headers = {"X-API-KEY": API_KEY, "Content-Type": "application/json"}

# Inline CSV data for demonstration; adjust to import a CSV
csv_data = [
    {"linkedin_url": "https://www.linkedin.com/in/john-doe"},
    {"linkedin_url": "https://www.linkedin.com/in/jane-doe"}
]

output_csv = "sales_leads.csv"

def get_mobile_number(linkedin_url):
    """Fetch mobile number using the /mobile-numbers/enrich endpoint."""
    try:
        payload = {"linkedin_url": linkedin_url}
        response = requests.post(f"{BASE_URL}/mobile-numbers/enrich", headers=HEADERS, json=payload)
        response.raise_for_status()  
        data = response.json()
        return data.get("mobile_number", "N/A")
    except requests.exceptions.RequestException as e:
        print(f"Error fetching mobile number for {linkedin_url}: {e}")
        return "Error"
2

Enrich Contact Data

Next, you’ll use the same LinkedIn URL to get details for the lead via the /contacts endpoint. You select certain fields that are available in the response, like their employment timeline, to help provide context for future interactions.
enrich-leads.py
def get_contact_details(linkedin_url):
    """Fetch contact details using the /contacts endpoint."""
    try:
        payload = {"linkedin_url": linkedin_url}
        response = requests.post(f"{BASE_URL}/contacts", headers=HEADERS, json=payload)
        response.raise_for_status()  
        if data.get("records"):
            contact = data["records"][0]
            return {
                "name": contact.get("name", "N/A"),
                "title": contact.get("title", "N/A"),
                "company": contact.get("company", "N/A"),
                "location": contact.get("location", "N/A"),
                "employment_timeline": contact.get("employment_timeline", "N/A"),
            }
        return {}
    except requests.exceptions.RequestException as e:
        print(f"Error fetching contact details for {linkedin_url}: {e}")
        return {}
3

Create Lead List

Finally, you’ll create a file you can reference that contains data obtained from both endpoints.
enrich-leads.py
def process_csv(data, output_csv):
    """Process the inline CSV data and generate an output CSV with enriched data."""
    try:
        with open(output_csv, "w", newline="") as outfile:
            fieldnames = [
                "linkedin_url", "mobile_number", "name", "title", "company", "location", "employment_timeline"
            ]
            writer = csv.DictWriter(outfile, fieldnames=fieldnames)
            writer.writeheader()

            for row in data:
                linkedin_url = row["linkedin_url"]
                print(f"Processing: {linkedin_url}")

                # Fetch data
                mobile_number = get_mobile_number(linkedin_url)
                contact_details = get_contact_details(linkedin_url)

                # Write to output CSV
                writer.writerow({
                    "linkedin_url": linkedin_url,
                    "mobile_number": mobile_number,
                    "name": contact_details.get("name", "N/A"),
                    "title": contact_details.get("title", "N/A"),
                    "company": contact_details.get("company", "N/A"),
                    "location": contact_details.get("location", "N/A"),
                    "employment_timeline": contact_details.get("employment_timeline", "N/A"),
                })
    except FileNotFoundError as e:
        print(f"Error writing to file {output_csv}: {e}")
    except IOError as e:
        print(f"File I/O error: {e}")

if __name__ == "__main__":
    try:
        process_csv(csv_data, output_csv)
        print(f"Sales leads enriched and saved to {output_csv}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
4

Run the Script

Save and run the script with:
Terminal
python3 enrich_leads.py
You should see output like:
Terminal
Processing: https://www.linkedin.com/in/john-doe
Processing: https://www.linkedin.com/in/jane-doe
Sales leads enriched and saved to sales_leads.csv
And your CSV might look like:
sales_leads.csv
linkedin_url,mobile_number,name,title,company,location,employment_timeline
https://www.linkedin.com/in/johndoe,5551234567,John Doe,Chief Executive Officer,Acme Corp,"New York, NY, United States","Acme Corp: Chief Executive Officer: 2015-01 to Present - Acme Corp: VP of Operations: 2010-01 to 2015-01 - GlobalTech: Senior Manager: 2005-06 to 2010-01"
https://www.linkedin.com/in/janedoe,5559876543,Jane Doe,Chief Marketing Officer,Globex Inc,"San Francisco, CA, United States","Globex Inc: Chief Marketing Officer: 2018-03 to Present - Globex Inc: Marketing Director: 2013-03 to 2018-03 - BrandWorks: Marketing Manager: 2008-05 to 2013-03"

Next Steps

In this tutorial, you built a complete enrichment script that:
  • Authenticates with the LeadX API
  • Sends LinkedIn URLs to fetch mobile numbers and contact data
  • Writes all enriched results into a CSV file
This structure is flexible and you can easily adapt it to read input from a CSV file, enrich hundreds of profiles, or integrate directly into your CRM pipeline.
Last modified on March 23, 2026