It’s no secret that data-driven decisions can make the sales processes much more efficient. Sales professionals rely on trusted data sources to scout for prospects. Crunchbase is one of the most trusted and extensive sources of data about companies. If the majority of your prospective customers reside on the Crunchbase database, then you are in luck. With the aid of Crunchbase API, you can set up a quick and easy mechanism to capture data that is relevant for your sales prospecting process.
In this tutorial, we are going to show you how to leverage the Crunchbase API with Python to build an automated prospect pipeline based on the company’s updates on Crunchbase. You’ll find a comprehensive tutorial with sample code and examples below. Íf, your sales outreach to a company, relies on its funding news, then you can get this information from the Crunchbase API.
Let’s take a look at the options available with Crunchbase API and build a demo application that you can run as a daily cronjob to extract the list of prospect companies.
How to get Access to the Crunchbase API
Crunchbase API has a long and exhaustive set of endpoints for querying information about organizations, their founders, and information related to funding, acquisitions, and more.
Follow the steps below to activate Crunchbase API with your RapidAPI account.
1. Sign Up for RapidAPI Account
To begin using the Crunchbase API, you’ll first need to sign up for a free RapidAPI developer account. With this account, you get a universal API Key to access all APIs hosted on RapidAPI.
RapidAPI is the world’s largest API marketplace, with over 10,000 APIs and a community of over 1,000,000 developers. Our goal is to help developers find and connect to APIs to help them build amazing apps.
2. Subscribe to Crunchbase API
Once signed in, log on to your RapidAPI account and access the Crunchbase API Console.
Now click on the “Pricing” tab and opt-in for the basic subscription that gives you unlimited free access to query organization and person-related attributes in Crunchbase ODM (Open Data Map).
3. Test Your API Subscription
Once subscribed, come back to the “Endpoints” tab on the API console. The endpoints of Crunchbase API are categorized into two groups, “ODM” and “Full Access Endpoints.”
With the basic subscription, your access is limited only to the ODM endpoints of Crunchbase API. The ODM endpoints contain the building blocks of the Crunchbase dataset, which is organizations and persons.
In this tutorial, we are going to use the “GET ODM Organizations” endpoint to retrieve the organization-specific attributes. Let’s do a test run of this endpoint.
Select the “GET ODM Organizations” endpoint from the endpoint list under the “ODM” category and enter the value for the parameter ‘updated_since’ as shown.
The parameter value contains a timestamp in UNIX time format, which translates to February 10, 2020, 00:00:00. Hit the “Test Endpoint” button. You should get an API response containing a list of all organizations that have got an update post this time.
Now, if you call this endpoint at the beginning of every day with the timestamp value in ‘updated_since’ set to the beginning of the previous day, then you get list companies that have updated their information on Crunchbase, during the previous day.
To trigger this endpoint programmatically, you can get a sample code snippet by choosing the programming language and library of your choice, here is how you would invoke this API endpoint using the Python requests library.
The most likely reason for updates on Crunchbase is funding. A new funding round for a prospect company is a good proposition for you as a sales rep. With the Crunchbase API, you can leverage the “GET ODM Organizations” endpoint to hunt down your prospect companies.
How to use the Crunchbase API with Python to get daily Sales Prospects
CrunchCron: Your Daily Source Of Prospects Powered By Crunchbase
With the new-found knowledge on Crunchbase API, you are all set to build your crunchcron script. We call it crunchcron since it runs as a cron job at the beginning of each day.
The output of each days’ scan is stored in a CSV (comma-separated value) file.
Without further ado, let’s jump into coding and build this script from scratch.
Before you start, make sure that you have the prerequisites set up on your computer for the development environment.
- Python 3 Runtime: You must have a Python 3 runtime installed.
- Requests library: You must have the requests library installed on your Python 3 runtime. You can use the pip command “ pip install requests” to install it.
Open your favorite code editor and create a new file named crunch_cron.py. Follow along the step below to build the code logic.
1. Define the imports and globals
To begin with, you have to import the libraries that are used in the script. The script also uses the RapidApi key to invoke the Crunchbase API. A global variable is defined to contain the key.
import sys import json import requests import csv from datetime import datetime, date, time, timedelta, timezone RAPIDAPI_KEY = “<YOUR_RAPIDAPI_KEY>”
Make sure to replace the placeholder <YOUR_RAPIDAPI_KEY> with your RapidApi subscription key.
2. Define a function for triggering Crunchbase API
Every Time the script runs, it makes a call to Crunchbase API. Let’s define a separate function for that.
def trigger_api(since_time): querystring = { "updated_since": str(since_time), "sort_order":"updated_at ASC"} headers = { 'x-rapidapi-host': "crunchbase-crunchbase-v1.p.rapidapi.com", 'x-rapidapi-key': RAPIDAPI_KEY } url = "https://crunchbase-crunchbase-v1.p.rapidapi.com/odm-organizations" response = requests.request("GET", url, headers=headers, params=querystring) if(200 == response.status_code): return json.loads(response.text) else: return None
The query string for the API call has two parameters, ‘updated_since’ and ‘sort_order’. We already know the significance of ‘updated_since’. The ‘sort_order’ defines the sorting order of the results.
3. Initialize the Script with Starting Data/Time
We now move to the main logic of the script. In the beginning, the script calculates the timestamp of the previous date. This timestamp is the value of ‘updated_since’ used as an input for the API call.
current_date = datetime.combine(date.today(), time(0, 0, 0)) yesterday_date = current_date - timedelta(days=1) yday_timestamp_utc = int(yesterday_date.replace(tzinfo=timezone.utc).timestamp()) print("Scanning Crunchbase API for company updates on " + yesterday_date.strftime("%m/%d/%YYYY")) print(yday_timestamp_utc) api_response = trigger_api(yday_timestamp_utc)
With the help of the Python datetime library, you get today’s date, which is the date and time reference. Using the reference, you move back one day and find the timestamp of the previous day, in UTC. The previous day’s timestamp becomes the input for the trigger_api( ) call.
4. Parse API Response Data and Dump Into CSV File
This is the last step in the process.
The API response returns a list of companies that are updated since the previous day’s timestamp. You run a loop to iterate through the array of companies and extract relevant information about them.
with open('Crunchbase_Updated-' + yesterday_date.strftime("%m-%d-%Y") + '.csv', 'w',newline='') as csv_file: csv_writer = csv.writer(csv_file) csv_writer.writerow(["Name","Homepage", "Update Timestamp"]) for org in api_response["data"]["items"]: try: org_name = org["properties"]["name"] org_url = org["properties"]["homepage_url"] org_update = str(org["properties"]["updated_at"]) print("Updated Company: " org_name) csv_writer.writerow([org_name,org_url,org_update]) except TypeError as e: print(e) print("Type Error...Ignoring") except csv.Error as e: print(e) print("CSV Error...Ignoring") csv_file.close()
Before the iteration, a new .csv file is created with the prefix “Crunchbase_Updated” along with the date stamp in DD-MM-YYYY format.
At every iteration, company name, homepage URL and the update timestamp is extracted and dumped into a row in the CSV file.
Finally, the script closes the file and exists.
Here is the actual script, complete with exception handling and scope definition for __main__ context.
import sys import json import requests import csv from datetime import datetime, date, time, timedelta, timezone RAPIDAPI_KEY = "<YOUR_RAPIDAPI_KEY>" def trigger_api(since_time): querystring = { "updated_since": str(since_time), "sort_order":"updated_at ASC"} headers = { 'x-rapidapi-host': "crunchbase-crunchbase-v1.p.rapidapi.com", 'x-rapidapi-key': RAPIDAPI_KEY } url = "https://crunchbase-crunchbase-v1.p.rapidapi.com/odm-organizations" response = requests.request("GET", url, headers=headers, params=querystring) if(200 == response.status_code): return json.loads(response.text) else: return None if __name__ == "__main__": try: current_date = datetime.combine(date.today(), time(0, 0, 0)) yesterday_date = current_date - timedelta(days=1) yday_timestamp_utc = int(yesterday_date.replace(tzinfo=timezone.utc).timestamp()) print("Scanning Crunchbase API for company updates on " + yesterday_date.strftime("%m/%d/%YYYY")) print(yday_timestamp_utc) api_response = trigger_api(yday_timestamp_utc) with open('Crunchbase_Updated-' + yesterday_date.strftime("%m-%d-%Y") + '.csv', 'w',newline='') as csv_file: csv_writer = csv.writer(csv_file) csv_writer.writerow(["Name","Homepage", "Update Timestamp"]) for org in api_response["data"]["items"]: try: org_name = org["properties"]["name"] org_url = org["properties"]["homepage_url"] org_update = str(org["properties"]["updated_at"]) print("Adding Company: " + org_name) csv_writer.writerow([org_name,org_url,org_update]) except TypeError as e: print(e) print("Type Error...Ignoring") except csv.Error as e: print(e) print("CSV Error...Ignoring") csv_file.close() except Exception as e: print("Major Exception ...Aborting") sys.exit(e)
Let’s Test The CrunchCron
After writing the code, it’s time to put the script to the test.
You can execute the script from the Python command line and see the generated CSV file. The file is created in the same location as the script. Here is a partial CSV output from one of the test runs, that contains companies that were updated since Feb 13th, 2020.
If you run this script as part of a cron job, then to get an exact list of companies updated during a previous date, you have to make sure that you configure the cron job to run at the beginning of each day, in UTC.
Time To Crunch Your Sales Prospects
With the crunchcron in operation, you can now automate the sales prospecting process by importing the CSV data to populate your prospect list. Go ahead and try out this script with your RapidAPI subscription.
If you need to capture more data about companies, then you can check the other company parameters returned in the API response and modify the script accordingly. Also, in case you are looking for more specific information, then a Pro subscription to Crunchbase API is your best source.
I’ve rewritten your code and while it runs, the csv file it generates is empty with an error code in the terminal of
1613692800
‘NoneType’ object is noit subscriptable.
Major Exception … Aborting.
This is a well-written script so I wanted to say thank you, but it’s not giving any data inside the CSV it is writing.
Perhaps the code has changed? I’ve gone back as far as 100 days and still get the same error but the datetime code changes accordingly