How to load data from HubSpot to Redshift

Blendo Team

This post will help you with syncing your HubSpot data to Amazon Redshift. By doing this you will be able to perform advanced analytics on a system that is designed for this kind of data, like Amazon Redshift. Alternatively, you can simplify the process of syncing data from HubSpot to Redshift by using Blendo, where the whole process will be handled by Blendo and you can focus on what matters, the analysis of your data.

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:

You will need more time to read this post than integrating Hubspot to Redshift.

Effortlessly Sync All Your Hubspot Data to Redshift

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 un official clients can be found.

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 to use 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 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.

  1. Integrations cannot consume the API at a rate greater than 10 requests/second.
  2. Polling of HubSpot APIs should occur at intervals of 5 minutes or more.
  3. Total requests to the APIs should not exceed 10,000 in a 24 hour period.
  4. Failed requests to the APIs may not exceed 5% of total syncs.
  5. All data passed to HubSpot must be properly encoded, and use application/json formatting.
  6. Integrations should use HubSpot’s OAuth protocol.
  7. 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.
  8. Integrators should use their own public and documented APIs when working with the HubSpot APIs.
  9. 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 products 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 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 the 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:

{
    "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.

About HubSpot

HubSpot is a suite of software offering two different customer related products:

  • HubSpot CRM. For Customer Relations Management.
  • HubSpot Marketing. Marketing platform, focusing mainly on inbound marketing.

HubSpot CRM offers a CRM platform that is connected to all the different channels and touchpoints where the modern sales process takes place. Channels like:

  • Landing pages
  • email
  • phone calls
  • social media

By using HubSpot CRM it is possible to control your content, channels and marketing performance from one single platform, making it much easier to have a birds eye view of your sales process. You can create customised views, it offers deal and task dashboards and it connects directly with HubSpot Marketing so you can effortlessly capture, score and hand off leads to your sales team.

HubSpot Marketing which was also the first product of HubSpot, offers the complete marketing funnel to its user, from attracting users to closing customers with less hassle and more control of the whole process. It focuses mainly on inbound marketing techniques related to the following:

  • Blogging
  • SEO
  • Social Media
  • Landing pages
  • Email campaigns

It allows you to easily perform lead management, it supports marketing automation like triggering mails when specific events happen on your landing page. It offers rich analytics and of course it integrates seamlessly with HubSpot CRM.

It is clear that HubSpot’s products generate a large number of valuable data related to your business, product and customers. While it offers analytic services, you might want to run some more engaged analysis with your HubSpot data, or merge these data with other sources like your ticketing system, your transaction database and logs or with user generated events from your product. HubSpot exposes a rich ecosystem of tools and APIs for interacting with its platform and it is possible by using these APIs to pull the data that are valuable to you from it.

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:

About Amazon Redshift

Amazon Redshift is one of the most popular data warehousing solutions which is part of the Amazon Web Services (AWS) ecosystem. It is a petabyte scale, fully managed data warehouse as a service solution that runs on the cloud. It is SQL based and you can communicate with it as you would do with PostgreSQL.

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:

  1. create a delivery stream
  2. 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.

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:

copy listing
from '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 Blendo that can handle this kind of problems automatically for you.

Blendo 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.

Help your marketing and executive team take ownership of the insights that live in your Hubspot marketing platform to transform the performance and ROI of your campaigns.

Blendo is the easiest way to automate powerful data integrations.

Try Blendo free for 14 days. No credit card required.