Creating diagrams from HubSpot automatically.
I love using HubSpot to organize my sales leads and to get an overview of my sales funnel. Because of that I use it for many projects and even for myself personally. In many situations, I need to get a quick overview of my funnel and/or send it to someone else, for example when writing reports for mentors or my startup's advisory board. That's why I created this script to generate diagrams of my sales funnel.
This Python script generates CSVs and diagrams for all of your Deal Pipelines automatically. Deal Pipelines are a custom deal funnel every sale has to go through, e.g. call
, meeting
, contact signed
. With the script, you can generate automated reports for your stakeholders, for example by including the resulting diagrams in a LaTeX report.
Running is as easy as
python3 main.py
The tool then executes two main tasks: It fetches the data, stores it in CSV files and generates diagrams from the stored files afterwards. This way, you can extend the csv data if you like or separate the data generation from the plotting. Here's how the two steps work in detail:
In the first step, the tool fetches your Deal Pipelines via the HubSpot API. For each pipeline it generates a folder named after the the pipline_id
(so don't worry if you see cryptic folders). The tool will then generate a CSV file named data.csv
in each folder that looks like this:
date,deals_closed,deals_funnel,deals_amount_closed,deals_amount_funnel
2017-06-25 23:26:34.209553,10,11.8,0,0
2017-06-26 12:17:54.598448,10,11.9,0,0
2017-06-26 12:18:36.467397,10,11.9,0,0
2017-06-26 16:22:50.843669,10,12.3,0,0
2017-06-26 19:02:31.730476,11,13.0,0,0
2017-06-27 00:38:35.257576,11,13.0,0,0
For every run, one row is appended to the CSV file consisting of the following columns:
datetime
value.The second step generates the plots and saves png files in the according folders. For each pipeline, there are two plots:
The title of each diagram will contain the name of the pipeline. You can find the results in the out
directory. The directory structure below shows the files inside the out directory:
├── config.py
├── hubspot
│ ├── api.py
│ ├── deals.py
│ └── __init__.py
├── main.py
├── out
│ ├── 666703db-8e54-49c1-be53-redacted
│ │ ├── data.csv
│ │ ├── deal_amount.png
│ │ └── deal_count.png
│ ├── 66659266-9d3f-41f3-8856-redacted
│ │ ├── data.csv
│ │ ├── deal_amount.png
│ │ └── deal_count.png
│ ├── default
│ │ ├── data.csv
│ │ ├── deal_amount.png
│ │ └── deal_count.png
│ ├── 666864eb-d814-4b5b-bfa1-redacted
│ │ ├── data.csv
│ │ ├── deal_amount.png
│ │ └── deal_count.png
│ └── overall
│ ├── data.csv
│ ├── deal_amount.png
│ └── deal_count.png
└── README.md
The installation is pretty straightforward. Make sure matplotlib
and requests
are installed, create a config.py
file as shown below, and run python main.py
periodically, for example by creating a daily cron job.
HUBSPOT_HAPIKEY = 'yourkeyhere'
You can generate an API key by clicking at your profile picture in HubSpot, then at Integrations
, and finally at HubSpot API key
.