As important as this report is for marketing and sales, it’s currently only available from HubSpot via their reporting add-on (for an additional $200+ per month fee). But even the report currently available through the HubSpot add-on didn’t quite fully cover our needs because some life cycle changes that our customers go through do not occur in HubSpot but rather inside our proprietary SherpaDesk app.
My task was to capture all our customer lifecycle stages on our SherpaDesk (Customer Support Service) API and update their records in HubSpot accordingly so that both systems were in sync. On top of that, we needed to be able to pull a report for a specific date range (i.e. last week, last month, etc.).
Hubspot does offer API access.
But many developers complain that its missing some important features like search by dates or custom fields. This was really a challenge of the tallest order: How do you create this report using the existing HubSpot API?
But if there's a will there’s a way.
Even if you only have a basic knowledge of Javascript, you can use HubSpot’s API to get user's info and then display this info as a HTML page. The trick was to add the other requirements of the brief: Date range and custom fields.
Let’s build this report in 3 easy steps.
To access HubSpot’s API you first need to obtain an API key.
The first issue you will encounter is trying to do an AJAX request to the API (this is a CORS issue).
To pass this you can use a free CORS wrapper like https://crossorigin.me/ Here is the sample code:
Now you can send any request to HubSpot’s API from Javascript.
Here is my function sample code:
Our UserHubSpotURL gets a list of all users from a specific index. I decided to get these users one by one and show them as a table.
According to API docs, “Lifecycle Stage denotes the stage at which the contact is in. Stages include 'subscriber', 'lead', 'marketing qualified lead', 'sales qualified lead', 'opportunity' and 'customer'. “
You need to pay attention to the fact that Lifecycle stages are not designed to move backwards. If you need to set this property to a previous stage, you will first need to set the value to "" (an empty string) and then set the new stage.
So you need to check the current and updated value:
HubSpot’s API is limited to collect all contacts or to search them by email, name, or company name only.
The only method we can use to get the dates when these contacts were created is GET /contacts/v1/lists/:list_id/contacts/recent
I got the idea to grab the most recent contacts and then use vidO set and timeO set to page backwards. When I reach my desired date period, I will then start to show records on the page.
As a result, the user will only see their date period of interest.
Here’s HubSpot’s notes on how to use vidO set & timeO set.
We start by using this query
(//api.hubapi.com/contacts/v1/lists/contacts/recent?hapikey=XXXX)
Which returns a list of contacts, and then the offsets:
And then we construct our next query as:
(//api.hubapi.com/contacts/v1/lists/contacts/recent?hapikey=XXXX&vidO se t=1111&timeO set=1311111111111)
To generate statistics on retrieved data you may need to export the results to Excel. This code snippet will help you:
You can use this data to generate any type of reports and statistics with Excel or other Javascript tools (i.e. GoJS.net, ChartJS)