In the world of B2B sales and marketing, data is king. But not all data is created equal. Stale, inaccurate, or incomplete information about your prospects can lead to wasted effort, missed opportunities, and flawed strategies. What if you could build a custom tool that not only finds new leads but also enriches them with up-to-the-minute, verified data?
This tutorial will guide you through building a powerful, yet simple, B2B prospecting tool using Python. We'll leverage the businesses.do API to go from a simple list of company domains to a qualified list of prospects that match your Ideal Customer Profile (ICP). Let's get building.
Category: Experiments
Off-the-shelf prospecting platforms are powerful, but they often come with high subscription costs and rigid workflows. Building your own tool offers several key advantages:
Our tool will be powered by the businesses.do API, a simple REST API designed for one thing: providing comprehensive and real-time data for millions of businesses worldwide.
With a single API call using a company domain, name, or ticker, you can retrieve a rich profile of firmographic data. Here’s a sample of the data you get back:
This rich, structured data is the perfect foundation for our prospecting script.
Let's get to the code. This practical tutorial will walk you through creating a script that qualifies leads based on industry, size, and location.
It's good practice to store your API key as an environment variable rather than hardcoding it in your script. For this tutorial, we'll assign it to a variable.
First, we need to define who we're looking for. For this example, let's say our ICP is:
We can define this in our script:
Let's create a reusable function that takes a domain, queries the businesses.do API, and returns the data.
Now for the core logic. We'll start with a list of domains to investigate. The script will loop through them, fetch the data, and check if each company matches our ICP.
Printing to the console is great for testing, but for a real workflow, you'll want to save the output. Let's add a function to export our qualified leads to a CSV file.
Now, when you run the full script, you'll get a qualified_leads.csv file on your computer, ready to be imported into your CRM or analyzed further.
This script is a fantastic starting point. Here are a few ideas to expand its capabilities:
You've just seen how to build a fully functional B2B prospecting tool with just a few lines of Python and the businesses.do API. By moving away from static data lists and embracing a real-time, programmatic approach, you can build a smarter, more efficient sales and marketing engine.
Ready to supercharge your B2B data workflows? Get your API key and start building with businesses.do today!
Q: What kind of data can I get with businesses.do?
A: You can access a wide range of data including company name, address, industry codes (SIC/NAICS), employee count, annual revenue, key contacts, and more.
Q: How up-to-date is the business data?
A: Our agentic workflows query multiple public and private data sources in real-time, ensuring you receive the most current information available at the time of your API call.
Q: Can I search for a business by its domain name?
A: Yes. The API allows you to find and verify businesses using various identifiers, including company name, domain, stock ticker, or even physical address.
Q: Is this service useful for sales and marketing teams?
A: Absolutely. Use businesses.do to enrich your CRM data, qualify leads, build targeted prospect lists, and gain deep insights into your target accounts, all programmatically.
{
"status": "success",
"query": {
"domain": "example.com"
},
"business": {
"name": "Example Corporation Inc.",
"legalName": "Example Corporation, Inc.",
"domain": "example.com",
"yearFounded": 1992,
"industry": "Software & Services",
"naicsCode": "511210",
"sicCode": "7372",
"employeeCount": 12500,
"annualRevenueUSD": 2400000000,
"location": {
"streetAddress": "123 Example Way",
"city": "Techville",
"state": "CA",
"postalCode": "90210",
"country": "USA"
},
"socialProfiles": {
"linkedin": "linkedin.com/company/examplecorp"
},
"isVerified": true
}
}
pip install requests
import requests
import os
import csv
# Replace 'YOUR_API_KEY' with your actual key from businesses.do
# For production, use environment variables: os.environ.get('BUSINESSES_DO_API_KEY')
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.businesses.do/v1/enrichment/business"
ICP_CRITERIA = {
"industry": "Software & Services",
"state": "CA",
"min_employees": 100,
"max_employees": 5000
}
def get_business_data(domain):
"""
Queries the businesses.do API for a given domain and returns the data.
"""
if not API_KEY or API_KEY == "YOUR_API_KEY":
print("Error: API Key not set. Please get your key from businesses.do")
return None
params = {
'domain': domain,
'apiKey': API_KEY
}
try:
response = requests.get(BASE_URL, params=params)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
data = response.json()
if data.get("status") == "success":
return data.get("business")
else:
print(f"Failed to get data for {domain}: {data.get('message')}")
return None
except requests.exceptions.RequestException as e:
print(f"An error occurred while calling the API for {domain}: {e}")
return None
def qualify_leads(domains, icp):
"""
Processes a list of domains and returns a list of qualified leads.
"""
qualified_leads = []
for domain in domains:
print(f"Processing {domain}...")
business_data = get_business_data(domain)
if business_data:
# Check if the business matches our ICP
employee_count = business_data.get("employeeCount", 0)
if (business_data.get("industry") == icp["industry"] and
business_data.get("location", {}).get("state") == icp["state"] and
icp["min_employees"] <= employee_count <= icp["max_employees"]):
print(f" -> QUALIFIED: {business_data.get('name')}")
qualified_leads.append(business_data)
else:
print(f" -> Not a fit for {business_data.get('name')}.")
print("-" * 20)
return qualified_leads
# Our list of potential prospects
prospect_domains = [
"google.com",
"openai.com",
"zapier.com",
"ycombinator.com",
"ford.com"
]
# Run the qualification process
qualified_companies = qualify_leads(prospect_domains, ICP_CRITERIA)
print("\n--- Qualified Leads Found ---")
for company in qualified_companies:
print(f"Name: {company['name']}, Employees: {company['employeeCount']}, Location: {company['location']['city']}, {company['location']['state']}")
def save_to_csv(companies, filename="qualified_leads.csv"):
"""
Saves a list of company data to a CSV file.
"""
if not companies:
print("No companies to save.")
return
# Define the headers for our CSV file
headers = ["name", "domain", "industry", "employeeCount", "annualRevenueUSD", "city", "state", "country"]
with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=headers, extrasaction='ignore')
writer.writeheader()
for company in companies:
# Flatten the location data for easier writing
row = company.copy()
row.update(company.get("location", {}))
writer.writerow(row)
print(f"\nSuccessfully saved {len(companies)} qualified leads to {filename}")
# After finding qualified companies, save them
save_to_csv(qualified_companies)