Setup Guide
This guide walks you through creating a HubSpot app and obtaining the credentials required to authenticate with the HubSpot CRM Leads API.
Prerequisites
- A HubSpot account. If you do not have one, sign up for a free HubSpot account.
Step 1: Create a HubSpot developer account
If you plan to use OAuth 2.0 (recommended for production), you need a HubSpot developer account to create a public app:
- Go to HubSpot Developer Portal and sign in.
- Click Create developer account if you do not already have one, or log in with your existing HubSpot credentials.
- Once logged in, navigate to Apps in the top navigation bar.
Step 2: Create a private app (API key: quickest setup)
For a simpler setup (ideal for development or internal integrations), create a Private App to obtain a token directly:
- Log in to your HubSpot account (not the developer portal).
- Click the Settings gear icon in the top navigation bar.
- In the left sidebar, navigate to Integrations → Private Apps.
- Click Create a private app.
- On the Basic Info tab, enter a name and (optionally) a description for your app.
- Switch to the Scopes tab and add the following scopes:
crm.objects.leads.readcrm.objects.leads.write
- Click Create app, then confirm by clicking Continue creating.
- Copy the generated Access Token; this is your
privateApptoken.
The Private App access token is shown only once at creation time. Copy and store it securely before closing the dialog.
Step 3: Create a public app for OAuth 2.0
For OAuth 2.0 (recommended for apps used by multiple HubSpot accounts):
- In the HubSpot Developer Portal, go to Apps and click Create app.
- Under App Info, provide an App name and (optionally) a description and logo.
- Navigate to the Auth tab.
- Note the Client ID and Client secret; you will need these later.
- Under Redirect URLs, add a redirect URI
(e.g.,
https://your-app.com/oauth/callback). - Under Scopes, add the following required scopes:
crm.objects.leads.readcrm.objects.leads.write
- Click Save changes.
Store the Client ID and Client Secret securely. Do not commit them to source control: use environment variables or Ballerina's configurable feature with a Config.toml file.
Step 4: Generate an OAuth 2.0 authorization code and refresh token
To obtain a refresh token using the Authorization Code flow:
-
Construct the following authorization URL, replacing the placeholders:
https://app.hubspot.com/oauth/authorize?client_id=<YOUR_CLIENT_ID>&redirect_uri=<YOUR_REDIRECT_URI>&scope=crm.objects.leads.read%20crm.objects.leads.write -
Open the URL in a browser. Log in to HubSpot and authorize the app.
-
HubSpot redirects to your redirect URI with a
codequery parameter. Copy the code. -
Exchange the 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 includes an
access_token,refresh_token, andexpires_in. Save therefresh_token; it is used to obtain new access tokens automatically.
Use a tool like Postman or curl to perform the token exchange in step 4.