How to load data from Hubspot to Google BigQuery
Extract your data from HubSpot
The Hubspot APIs are following the REST architecture, which can be accessed through HTTP. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework.
A few suggestions:
- Apache HttpClient for Java
- Spray-client for Scala
- Hyper for Rust
- Ruby rest-client
- Python http-client
Responses of the API are all in JSON, including errors although HTTP codes are also returned to indicate errors. Hubspot maintains some official SDKs for their APIs, like the hapipy client for python, also unofficial clients can be found.
- haPiHP PHP wrapper for the APIs.
- Ruby Wrapper (unofficial).
Hubspot API Authentication
Hubspot API allows two types of authentication. OAuth and API keys. Hubspot encourages the use of oAuth for any serious integration and suggests using basic authentication with API keys only for testing and rapid prototyping purposes.
Hubspot API rate limiting
HubSpot public endpoints are powered by the same underlying technology that powers the core HubSpot application. As a result, HubSpot engineering closely monitors usage of the public APIs to ensure a quality experience for users of a HubSpot application.
Below, you’ll find the limits by which a single integration (as identified by an access token) can consume HubSpot public APIs.
- Integrations cannot consume the HubSpot API at a rate greater than 10 requests/second.
- Polling of HubSpot APIs should occur at intervals of 5 minutes or more.
- Total requests to the HubSpot APIs should not exceed 10,000 in a 24 hour period.
- Failed requests to the HubSpot APIs may not exceed 5% of total syncs.
- All data passed to HubSpot must be properly encoded, and use application/json formatting.
- Integrations should use HubSpot’s OAuth protocol.
- Integrators must store time-to-live (TTL) data for OAuth access tokens as well as refresh tokens. Unauthorized (401) requests are not a valid indicator that a new access token must be retrieved.
- Integrators should use their own public and documented APIs when working with HubSpot APIs.
- We reserve the right to change or deprecate the APIs over time – we will provide developers ample notification in those cases.
Endpoints and available Resources
Hubspot API is actually a collection of a large number of APIs. Something that makes sense if we consider that Hubspot is actually more than one product and each one of these products is quite complex on its own. The APIs are the following:
- Calendar API. Anything that has to do with calendars in Hubspot and their possible operations.
- Companies APIs. When we talk about business and customers we talk about companies, so here is your API for interacting with companies.
- Companies properties APIs. Companies are important for Hubspot and there’s a lot of functionality around them so there’s an auxiliary API just for working with properties of companies.
- Contacts APIs. Contacts are the fundamental building block to HubSpot – they store lead-specific data that makes it possible to leverage much of the functionality in HubSpot, from marketing automation, to lead scoring to smart content.
- Contact Lists APIs. API for managing the lists of your contacts.
- Contact properties APIs. Similar to companies, this API allows you to interact with the properties of your contacts.
- COS Blog API. Interact with Blogs throughs the Hubspot platform.
- COS Blog Authors API. API for interacting with the authors of your blogs.
- COS Blog Comments API. Exposes functionality about the comments of your APIs.
- COS Blog Posts API. Anything related to the posts of your Blog.
- COS Blog Topics API. Manage the topics of your Blog.
- COS Domains API. Manage your Domains through this API.
- COS Files API. Operations concerning file management inside Hubspot.
- COS Layouts API. Manage the layouts of your pages through this API.
- COS Page Publishing API. Operations linked with publishing content through Hubspot’s platform.
- COS Sitemaps API. Operations related to the management of sitemaps for the sites you create through the Hubspot platform.
- COS Templates API. API for managing the templates of your sites.
- COS URL Mappings API. Operations for URL mappings for the sites inside Hubspot.
- Deals API. Anything that has to do with deals inside your CRM.
- Deal Pipelines API. Manage the sales pipelines through this API.
- Deals Properties API. Again, manage the properties of your deals.
- Email API. Anything about emailing from within the HubSpot platform.
- Email Events API. Track and interact with events that happen inside emails.
- Engagements API. Anything related to customer engagement inside the HubSpot platform.
- Events API. Event handling for Hubspot.
- Forms API. Manage custom forms that you create inside the platform.
- Keywords API. Operations about keywords for SEO.
- Owners API. Anything related to the Owner.
- Social Media API. API for interacting with Social media through Hubspot’s platform.
- Transactional Email API. The transactional email functionality of Hubspot.
- Workflows API. Define and manage sales and marketing workflows.
From all the above endpoints we can pull data out of the platform, so it is easy to understand the richness of the data we can get from a platform like Hubspot. Let’s assume, as an example, that we want to get all the Deals data. By executing a GET request like this GET /deals/v1/deal/recent/modified we can get all the recently modified deals. The parameters that we can pass to the call are the following:
- count: for specifying the number of results per page of the response.
- offset: for paginating through all available results.
- since: a timestamp for defining from which exact time you would like to fetch data from.
As we said earlier, results from a Hubspot API are always in JSON, so if we successfully execute the above query we’ll get the following results back:
JSON
{"results": [{"portalId": 62515,"dealId": 1030663,"isDeleted": false,"associations": {"associatedVids": [27316],"associatedCompanyIds": [],"associatedDealIds": []},"properties": {"dealstage": {"value": "closedwon","timestamp": 1417686612442,"source": "API","sourceId": null,………
The API offers you the opportunity to get very granular data about your accounting activities and use it for analytic and reporting purposes.
Prepare your data to be sent from Hubspot to Google BigQuery
Before you load any data into BigQuery, you should make sure that it is presented in a format supported by it, so for example if the API you pull data from returns XML you have to first transform it into a serialization that BigQuery understands. Currently, two data formats are supported:
You also need to make sure that the data types you are using are the ones supported by BigQuery, which are the following:
- STRING
- INTEGER
- FLOAT
- BOOLEAN
- RECORD
- TIMESTAMP
for more information please check the Preparing Data for BigQuery page on the documentation.
Load Data using Hubspot to Google BigQuery
If you want to load any data using Hubspot to BigQuery, you have to use one of the following supported data sources.
- Google Cloud Storage
- Sent data directly to BigQuery with a POST request
- Google Cloud Datastore Backup
- Streaming insert
- App Engine log files
- Cloud Storage logs
From the above list of sources, 5 and 6 are not applicable in our case.
For Google Cloud Storage, you first have to load some data into it, there are a few options on how to do this, for example, you can use the console directly as it is described here and do not forget to follow the best practices. Another option is to post your data through the JSON API, as we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse.. In its simplest case it’s just a matter of one HTTP POST request using a tool like CURL or Postman. It should look like the following example.
SH
POST /upload/storage/v1/b/myBucket/o?uploadType=media&name=myObject HTTP/1.1Host: www.googleapis.comContent-Type: application/textContent-Length:
number_of_bytes_in_file
SH
Authorization: Bearer
your_auth_token your HubSpot data
and if everything went ok, you should get something like the following as a response from the server:
SH
HTTP/1.1 200Content-Type: application/json{"name": "myObject"}
Working with Curl or Postman is good only for testing, if you would like to automate the process of loading data into Bigquery, you should write some code to send your data to Google Storage in the Cloud. In case you are developing on the Google App Engine you can use the library that is available for the languages that are supported by it:
If you are using one of the above languages and you are not coding for the Google App Engine, you can use it to access the Cloud Storage from your environment. Interacting such a feature-rich product like Cloud Storage can become quite complicated depending on your use case, for more details on the different options that exist you can check Cloud Storage documentation. If you are looking for a less engaged and more neutral way of using Cloud Storage, you can consider a solution like RudderStack.
After you have loaded your data into the Storage in Google Cloud, you have to create a Load Job for BigQuery to actually load the data into it, this Job should point to the source data in Cloud Storage that have to be imported, this happens by providing source URIs that point to the appropriate objects.
The previous method described, used a POST request to the Google Cloud for Storage API for storing the data there and then load it into BigQuery. Another way to go is to do a direct HTTP POST request to BigQuery with the data you would like to query. This approach is similar to how we loaded the data to Storage in the Google Cloud through the JSON API, but it uses the appropriate end-points of BigQuery to load the data there directly. The way to interact with it is quite similar, for more information can be found on the Google BigQuery API Reference and on the page that describes how you can load data into BigQuery using POST. You can interact with, by using the HTTP client library of the language or framework of your choice, a few options are:
- Apache HttpClient for Java
- Spray-client for Scala
- Hyper for Rust
- Ruby rest-client
- Python http-client
The best way to load data from Hubspot to BigQuery
So far we just scraped the surface of what you can do with BigQuery and how you can load data into it. Things can get even more complicated if you want to integrate data coming from different sources.
Are you striving to achieve results right now?
Instead of writing, hosting, and maintaining a flexible data infrastructure use RudderStack that can handle everything automatically for you.
RudderStack with one click integrates with sources or services, creates analytics-ready data, and syncs your Hubspot to BigQuery right away.