Welcome to the "HubSpot API Quick Start Guide," a comprehensive resource designed to help you seamlessly integrate with HubSpot's powerful suite of tools. Whether you're new to APIs or an experienced developer, this guide will walk you through the essentials of working with the HubSpot API.
From understanding the fundamentals of HubSpot's data structures to navigating the complexities of OAuth 2.0 authorisation, this guide is intended to provide you with all the information you need to get started on integrating with the HubSpot API, quickly and effectively.
A brief overview of the different types of CRM Objects, Association and Engagements.
We take a look at all the critical components of getting up and running with your integration. A high level overview of REST, API limitations, Authorization, Authentication and Webhooks.
Also included in this guide is a mock brief, outlining the steps you need to take to map out the data and endpoint requirements - a crucial step in effective planning.
A example of the spec you would have received from the client, outlining the actions that need to map to endpoints, as well as the data that would be required to sync.
An example of a typical data relationship mapping spreadsheet. Thereafter the endpoint mapping, outlining the specific API endpoints they are integrating with.
The best handpicked resources on HubSpot API.
The main object architecture for HubSpot is simplified into 4 primary categories: contacts, companies, deal and tickets.
There are other subtypes as well; Products, Quotes, Engagements, Timeline Events, Notes. We’re not going into detail on these but you can read more about the different objects here.
Additionally, the HubDB is a customizable database(like a spreadsheet) that is typically used to store non-sensitive, relational data.
All information pertaining to an individual person. Uniquely identified by email address and VID(canonical-vid).
Similar in structure to Contacts, except pertaining to individual companies. Uniquely identified by Company Domain Name and companyID.
All information pertaining to an individual deal in your CRM pipeline. Any activities that are attributed to revenue needs to be created as a deal so that it can be tracked and ROI measured. Uniquely identified by dealID.
Information on an individual ticket. Similar to Deal objects, these tickets are added to a ticket board that is customized to match your processes (like a pipeline). Uniquely identified by objectID.
These spreadsheet-like tables are mostly used for storing relational data that is used for supporting features or processes like dynamic content, widget functionality, pricing or pricing tier calculations, resource libraries and more. HubDB tables can be public (CORS enabled), or private (authentication required). Public tables have a rate limit of 10 req/per second, while private tables adhere to default rate limits(see API Overview below).
CRM objects can be associated with each other, creating a relationship between records. There are 3 different association methods; Automatic, Manual and association via the API:
This feature is a setting that is activated in HubSpot, which will automatically associate records based on specific criteria. An example of this is ‘Automatically create and associate companies with contacts’; if a company domain name matches a contact email domain, the contact and company will be automatically associated, or if the company doesn’t exist it will be created and associated.
You are able to update association on individual records via the relevant record dashboards. Or you can do bulk association via importing and merging data with a spreadsheet.
Essentially the same as manual association but via the HubSpot API. Each association type has a specific corresponding ID and is done through the CRM Associations API. Additionally, knowing what unique IDs are required for association can be seen in the Entity Relationship Diagram below:
* HubSpot ERD Diagram – courtesy of HubSpot.
Engagements store data related to actions or activities done in your CRM. They are the interactions someone would have with a prospect/customer. These include notes, tasks, emails, meetings, and calls. The Engagement API is used to create engagements from external systems (logging calls, emails, notes) or extract engagement data for reporting.
REST Architecture
HubSpot API’s use a REST architecture. This includes most standard HTTP features like HTTP verbs (get, put, post). All calls are made to the api base domain https://api.hubapi.com and specific endpoints have predictable, descriptive URL structures. All data is in JSON format, including all response codes that indicate API errors.
Limits
Access to APIs are limited to the product tier/level that you are subscribed to (starter/pro/enterprise). Though, it should be noted that very few limitations are in place in this regard. See complete list of API limits by tiers here.
Furthermore, all calls to the HubSpot APIs are subject to rate limiting. These limits are also determined by your product tier. The standard is 250,000 total calls per day and a maximum 100 requests per 10 seconds.
See a full breakdown of rate limits here.
Integrations that exceed their limits will receive an error 429 response code.
Authorization
There are two ways of authentication; API key and OAuth 2.0.
API keys should only be used for prototyping. For security reasons, in commercial production you should always use OAuth.
The first step in Authentication is Authorization. To do this you have to create and register an app in a developer account. This will provide you with your Client ID and Secret Key, which is used to initiate the OAuth handshake between HubSpot and your integration.
OAuth allows you to authorize your integration to work with specific components of the HubSpot API by assigning authorization scopes. Each scope defines access to different parts of the HubSpot API. You can view the full list of available scopes here.
Below is a high-level overview of the authorization process:
Authentication
Once authorization is complete, you will have received a Refresh Token and an Access Token.
The Access token is used to authenticate calls made to the HubSpot API. This token expires after a specified amount of time (default 6 hours) and you use the Refresh Token to request a new Access Token.
Below are a few examples of this process, but it’s recommended to read this step-by-step guide for detailed information on authorization and authentication.
– authorizing the integration with specified scope, provides authorization code:
Example Authorization URL:
Sending a user to this URL will ask the user to approve access to contacts and workflows:
https://app.hubspot.com/oauth/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&scope=contacts%20automation&redirect_uri=https://www.example.com/
If they grant access, the user would be redirected to this URL:
https://www.example.com/?code=xxxx
If there are any problems with the authorization, you'll get the error parameters instead of the code:
https://www.example.com/?error=error_code&error_description=Human%20readable%20description%20of%20the%20error
– using the previously obtained auth code to generate the Refresh and Access Tokens:
POST URL:
https://api.hubapi.com/oauth/v1/token
Headers:
Content-Type: application/x-www-form-urlencoded;charset=utf-8
Data:
grant_type=authorization_code&client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&client_secret=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy&redirect_uri=https://www.example.com/&code=zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz
If successful, you will receive a JSON response with the tokens:
{
"access_token": "xxxx",
"refresh_token": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
"expires_in": 21600
}
- authenticating calls to the API using the provided Access Token:
{
headers: {
'Authorization': `Bearer ${ACCESS_TOKEN}`,
'Content-Type': 'application/json'
}
}
* Code Samples – courtesy of HubSpot.
Webhooks
The Webhooks API allows you to trigger HTTP requests to a specified endpoint based on events in HubSpot. This allows for a better alternative to polling, saving on rate limits and providing a more scalable method of bi-directional data sync.
Webhook subscriptions are configured on your app dashboard, in your developer account. There are various event subscriptions available (contact created, deleted, contact property updated etc). Below is a link to the full list of available subscriptions.
Below is a sample specification, that your client might provide. It's a high-level overview, describing the endpoint and data requirements:
Object Relationship Mapping
The next step in the process is determining the exact data you wish to sync and then mapping the object relationships between HubSpot and your existing system. Based on this mapping you will be able to determine field types, object types, one or bi-directional requirements as well as identify any custom properties that would need to be created in HubSpot.
See the data mapping based on provided data requirements below:
External System Name |
HubSpot Name |
Object Type |
Property Type |
Notes |
|
|
CONTACT |
Single line text |
|
name |
* |
CONTACT |
Single line text |
* Custom property to be created |
first name |
firstname |
CONTACT |
Single line text |
|
last name |
lastname |
CONTACT |
Single line text |
|
role |
job_function |
CONTACT |
Single line text |
|
How did you discover us |
* |
CONTACT |
Single line text |
* Custom property to be created |
subscribe newsletter |
* |
CONTACT |
Single checkbox |
* One property for each newsletter type (to be created) |
subscription type |
* |
CONTACT |
Dropdown |
* Custom property to be created |
company |
company |
CONTACT |
Single line text |
|
country |
country |
CONTACT |
Single line text |
|
number |
phone |
CONTACT |
Single line text |
|
more info |
* |
CONTACT |
Single line text |
* Custom property to be created |
subject |
hs_ticket_category |
TICKET |
Multi-checkboxes |
|
support text |
content |
TICKET |
Multi-line text |
|
project count |
* |
CONTACT |
Number |
* Custom property to be created |
project person count |
* |
CONTACT |
Number |
* Custom property to be created |
file size |
* |
CONTACT |
Number |
* Custom property to be created |
remaining capacity |
* |
CONTACT |
Number |
* Custom property to be created |
* Note – These assumptions need to be discussed in detail with your client. In this example there are potential use cases for using Deals to track memberships, or potentially use automation workflows to determine expiry dates. All this should be discussed in a workshop session with your client.
Endpoints
After you’ve mapped each property to it’s corresponding equivalent in HubSpot, you can start reviewing the individual endpoint requirements.
All endpoints are well documented and it’s recommended reading the Overview for each endpoint you plan on using. This is where you will find endpoint specific requirements, limit information, use cases, response messages and other related information.
Below is a breakdown of your endpoint requirements, based on provided specification:
Action |
Type |
Endpoint |
Verb |
Link to Guide |
Register for trial account |
Contacts API |
/contacts/v1/contact/email/:email/profile |
POST |
|
User cancels account |
Contacts API |
/contacts/v1/contact/email/:email/profile |
POST |
|
Contact form |
Option 1: Contacts API |
/contacts/v1/contact/email/:email/profile |
POST |
|
Contact form |
Option 2: Forms API |
/uploads/form/v2/:portal_id/:form_guid |
POST |
|
Contact form |
Option 3: Use HubSpot Form |
Replace contact form with HubSpot form |
- |
|
Contact form |
Option 4: Use Non-HS Form |
The HubSpot embed allows tracking of forms |
- |
|
News letter |
Email Subscription API |
/email/public/v1/subscriptions/:email_address |
PUT |
|
Newsletter: Get Subscription IDs |
Email Subscription API |
/email/public/v1/subscriptions |
GET |
|
Support form |
Tickets API |
/crm-objects/v1/objects/tickets |
POST |
|
Support form: Get Contact VID |
Contacts API |
/contacts/v1/contact/email/:contact_email/profile |
GET |
|
Support form: Associate Ticket to Contact |
CRM Association API |
/crm-associations/v1/associations |
PUT |
|
Additional |
||||
Create deal |
Deals API |
/deals/v1/deal/ |
POST |
|
Get deal ID |
Deals API |
/deals/v1/deal/:dealId |
GET |
|
Update deal |
Deals API |
/deals/v1/deal/:dealId |
PUT |
|
Associate Contact to Deal |
CRM Association API |
/crm-associations/v1/associations |
PUT |
* Note – all endpoints use the following base URL: https://api.hubapi.com/ (except in a few instances like the Forms API, which is a public endpoint).
* Note – The required data structure for each request can be found in the provided guide links.
HubSpot has an extensive knowledge base and should provide everything else you need to get started. Below is a collection of the most useful resources on the HubSpot API:
HubSpot Academy
HubSpot GitHub Samples
API Documentation
HubSpot API Community
HubSpot Developer Slack Channel
In conclusion, this guide equips you with the knowledge and tools needed to harness HubSpot API's potential. With the ability to seamlessly integrate HubSpot into your applications, you can supercharge your marketing, sales, and customer service efforts and if you’re ready to take your integration to the next level, don't hesitate to book a call with our experts. Our team at Struto is here to assist you every step of the way.