How to load data from the HubSpot to Redshift
Extract your data from HubSpot
HubSpot APIs are following the REST architecture that 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’s 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
The public endpoints are powered by the same underlying technology that powers the core HubSpot application. As a result, HubSpot engineering closely monitors the usage of the public APIs to ensure a quality experience for users of the HubSpot application.
Below, you’ll find the limits by which a single integration (as identified by an access token) can consume the HubSpot public APIs.
- Integrations cannot consume the 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 APIs should not exceed 10,000 in a 24 hour period.
- Failed requests to the 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 the HubSpot APIs.
- We reserve the right to change or deprecate the APIs over time – we will provide developers with ample notification in those cases.
Endpoints and Available Resources
The 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.
- 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 through the HubSpot platform.
- COS Blog Authors API. API for interacting with the authors of your blogs.
- COS Blog Comments API. Exposes functionality related to 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. File management inside HubSpot.
- COS Layouts API. Manage the layouts of your pages through this API.
- COS Page Publishing API. Operations related to publishing content through HubSpot.
- COS Sitemaps API. Management of sitemaps for the sites you create through HubSpot.
- COS Templates API. API for managing the templates of your sites.
- COS URL Mappings API. Operations related to 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 related to emailing from within HubSpot.
- Email Events API. Track and interact with events that happen inside emails.
- Engagements API. Anything related to customer engagement inside HubSpot’s platform.
- Events API. Event handling for HubSpot.
- Forms API. Manage custom forms that you create inside the platform.
- Keywords API. Keyword-related operation for SEO.
- Owners API. Anything related to the Owner.
- Social Media API. API for interacting with Social media through the HubSpot 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 the 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 analytics and reporting purposes.
Prepare your HubSpot Data for Amazon Redshift
Amazon Redshift is built around industry-standard SQL with added functionality to manage very large data sets and high-performance analysis. So, in order to load data into it, you will have to follow its data model which is a typical relational database model. The data you extract from a data source should be mapped into tables and columns.
Where you can consider the table as a map to the resource you want to store and columns the attributes of that resource. Also, each attribute should adhere to the datatypes that are supported by Redshift, currently, the datatypes that are supported are the following:
- SMALLINT
- INTEGER
- BIGINT
- DECIMAL
- REAL
- DOUBLE PRECISION
- BOOLEAN
- CHAR
- VARCHAR
- DATE
- TIMESTAMP
As the data are probably coming in a representation like JSON that supports a much smaller range of data types you have to be really careful about what data you feed into Redshift and make sure that you have mapped your types into one of the datatypes that are supported by Redshift. Designing a Schema for Redshift and mapping the data from your data source to it is a process that you should take seriously as it can both affect the performance of your cluster and the questions that you can answer.
It’s always a good idea to have in your mind the best practices that Amazon has published regarding the design of a Redshift database. When you have concluded on the design of your database you need to load the data on one of the data sources that are supported as input by Redshift, these are the following:
Load data from HubSpot to Redshift
The first step to load your HubSpot data to Redshift is to put them in a source that Redshift can pull it from. As it was mentioned earlier there are three main data sources supported, Amazon S3, Amazon DynamoDB, and Amazon Kinesis Firehose, with Firehose being the most recent addition as a way to insert data into Redshift.
To upload data to Amazon S3 you will have to use the AWS REST API, as we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse. The first task that you have to perform is to create a bucket, you do that by executing an HTTP PUT on the Amazon AWS REST API endpoints for S3.
You can do this by using a tool like CURL or Postman. Or use the libraries provided by Amazon for your favorite language. You can find more information by reading the API reference for the Bucket operations on Amazon AWS documentation.
After you have created your bucket you can start sending data to Amazon S3, using again the same AWS REST API but by using the endpoints for Object operations. As in the Bucket case you can either access the HTTP endpoints directly or use the library of your preference.
DynamoDB imports data again from S3, it adds another step between S3 and Amazon Redshift so if you don’t need it for other reasons you can avoid it.
Amazon Kinesis Firehose is the latest addition as a way to insert data into Redshift and offers a real-time streaming approach into data importing. The necessary steps for adding data to Redshift through Kinesis Firehose are the following:
- create a delivery stream
- add data to the stream
whenever you add new data to the stream, Kinesis takes care of adding these data to S3 or Redshift, again going through S3, in this case, is redundant if your goal is to move your data to Redshift. The execution of the previous two steps can be performed either through the REST API or through your favorite library just as in the previous two cases. The difference here is that for pushing data into the stream you’ll be using a Kinesis Agent.
Amazon Redshift supports two methods for loading data into it. The first one is by invoking an INSERT command.
JAVASCRIPT
insert into category_stage values(12, 'Concerts', 'Comedy', 'All stand-up comedy performances');
The way you invoke the INSERT command is the same as you would do with any other SQL database, for more information you can check the INSERT examples page on the Amazon Redshift documentation.
Redshift is not designed for INSERT like operations, on the contrary, the most efficient way of loading data into it is by doing bulk uploads using a COPY command. You can perform a COPY command for data that lives as flat files on S3 or from an Amazon DynamoDB table.
When you perform COPY commands, Redshift is able to read multiple files in simultaneously and it automatically distributes the workload to the cluster nodes and performs the load in parallel. As a command COPY is quite flexible and allows for many different ways of using it, depending on your use case. Performing a COPY on Amazon S3 is as simple as the following command:
JAVASCRIPT
copy listingfrom 's3://mybucket/data/listing/'credentials 'aws_access_key_id=;aws_secret_access_key=';
For more examples on how to invoke a COPY command, you can check the COPY examples page on Amazon Redshift documentation.
The best way to load data from HubSpot to Redshift and possible alternatives
So far we just scraped the surface of what can be done with Amazon Redshift and how to load data into it. The way to proceed relies heavily on the data you want to load, from which service they are coming from, and the requirements of your use case. Things can get even more complicated if you want to integrate data coming from different sources.
A possible alternative, instead of writing, hosting, and maintaining a flexible data infrastructure, is to use a product like RudderStack that can handle this kind of problem automatically for you.
RudderStack integrates with multiple sources or services like databases, CRM, email campaigns, analytics, and more. Quickly and safely move all your data from HubSpot to Redshift and start generating insights from your data.