Learn how set up OAuth for your app using this quickstart Guide and sample Node.js app.
Fields marked with * are required.
Parameter | Description | Example |
---|---|---|
client_id * | The client ID identifies your app. Find it on your app’s settings page. | 7fff1e36-2d40-4ae1-bbb1-5266d59564fb |
scope * | The scopes your application is requesting, separated by URL-encoded spaces (%20 ). | oauth%20crm.objects.contacts.read |
redirect_uri * | The URL that the user will be redirected to after they authorize your app for the requested scopes. For production applications, https is required. | https://www.example.com/auth-callback |
optional_scope | The scopes that are optional for your app, and will be dropped if the selected HubSpot portal does not have access to those products | automation |
state | A unique string value that can be used to maintain the user’s state when they’re redirected back to your app. | WeHH_yy2irpl8UYAvv-my |
userA.integration.com
and userB.integration.com
). To do so, use the state
parameter to encode more information about the user state:
1. Generate and store a nonce value for the state parameter.
2. Store the user’s state in a local datastore using the nonce as its key.
3. Include the nonce value as the state parameter in the authorization URL.
4. When the user authenticates and is redirected to your redirect URL, validate the state parameter and use it as the key to retrieve the user state that was stored.
5. From there, redirect the user as needed (e.g. redirecting again to a user specific URL).
GET
request to the redirect URI specified in your authentication URL. If there are no issues and the user approves the access request, the request to the redirect URI will be returned with a code
query parameter attached. If the user doesn’t grant access, no request will be sent.
Example:
POST
request to https://api.hubapi.com/oauth/v1/token
with the values shown below. For more detailed information on this step, take a minute to read this reference doc.
Parameter | Description | Example |
---|---|---|
grant_type | Must be authorization_code | authorization_code |
client_id | Your app’s client ID | 7fff1e36-2d40-4ae1-bbb1-5266d59564fb |
client_secret | Your app’s client secret | 7c3ce02c-0f0c-4c9f-9700-92440c9bdf2d |
redirect_uri | The redirect URI from when the user authorized your app | https://www.example.com/auth-callback |
code | The authorization code received from the OAuth 2.0 server | 5771f587-2fe7-40e8-8784-042fb4bc2c31 |
expires_in
field of the response, currently 30 minutes. For details on getting a new access token, see the Refreshing OAuth tokens section below.Authorization
HTTP header. Specific details can be found in the reference doc.
Example:
crm.objects.contacts.read
scope, the resulting access token can view all contacts in the account and not only those owned by the authorizing user.expires_in
field when an authorization code is exchanged for an access token.
Your app can exchange the received refresh token for a new access token by sending a URL-form encoded POST
request to https://api.hubapi.com/oauth/v1/token
with the values below. For more detailed information on this step, check out the reference doc.
Parameter | Description | Example |
---|---|---|
grant_type | Must be refresh_token | refresh_token |
client_id | Your app’s client ID | 7fff1e36-2d40-4ae1-bbb1-5266d59564fb |
client_secret | Your app’s client secret | 7c3ce02c-0f0c-4c9f-9700-92440c9bdf2d |
redirect_uri | The redirect URI from when the user authorized your app | https://www.example.com/auth-callback |
refresh_token | The refresh token received when the user authorized your app | b9443019-30fe-4df1-a67e-3d75cbd0f726 |