Setup Guide
This guide walks you through creating a HubSpot app and obtaining the OAuth 2.0 credentials (or private app token) required to use the HubSpot CRM Deals connector.
Prerequisites
- A HubSpot account. If you do not have one, sign up for a free account.
- A HubSpot developer account for creating apps. Register at the HubSpot Developer Portal.
Step 1: Create a HubSpot developer app
- Log in to your HubSpot Developer Portal.
- Click Apps in the top navigation, then click Create app.
- Enter an App name (e.g.,
Ballerina Deals Integration) and optionally a description. - Click Create app.
Step 2: Configure OAuth scopes
- In your app settings, navigate to the Auth tab.
- Under Scopes, add the following required scopes:
crm.objects.deals.read: to read deal recordscrm.objects.deals.write: to create, update, and archive deals
- Set the Redirect URL to a URL you control (e.g.,
https://localhost:9090/callback). - Click Save.
Copy the Client ID and Client Secret from the Auth tab; you will need them in subsequent steps.
Step 3: Authorize the app and get an authorization code
-
Construct the following authorization URL, replacing the placeholders with your values:
https://app.hubspot.com/oauth/authorize?client_id=<YOUR_CLIENT_ID>&redirect_uri=<YOUR_REDIRECT_URI>&scope=crm.objects.deals.read%20crm.objects.deals.write -
Open the URL in a browser and log in to your HubSpot account.
-
Select the HubSpot account (portal) you want to connect, then click Grant access.
-
After authorization, HubSpot redirects to your
redirect_uriwith acodequery parameter. Copy thatcodevalue.
Step 4: Exchange the authorization code for a refresh token
Send the following POST request to exchange your authorization code for tokens:
POST https://api.hubapi.com/oauth/v1/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=<AUTHORIZATION_CODE>
&client_id=<YOUR_CLIENT_ID>
&client_secret=<YOUR_CLIENT_SECRET>
&redirect_uri=<YOUR_REDIRECT_URI>
The response contains access_token, refresh_token, and expires_in. Save the refresh_token; it is long-lived and used to obtain new access tokens automatically.
Use a tool like Postman or curl to perform the token exchange.
Step 5: Alternative: use a private app token
If you prefer not to use OAuth 2.0, HubSpot Private Apps provide a simpler API key approach:
- In your HubSpot account, click the Settings gear icon.
- Navigate to Integrations > Private Apps.
- Click Create a private app.
- Give it a name, then under Scopes add
crm.objects.deals.readandcrm.objects.deals.write. - Click Create app, then Continue creating.
- Copy the generated Access token; this is your
privateAppkey.
Private app tokens do not expire but should be stored securely and rotated if compromised.