OAuth is a secure means of authentication for your app. It uses authorization tokens rather than a password to connect your app to a user account.
/oauth/
and /authorize
, as shown below. After granting access, they’ll be redirected back to your application via a redirect_url
, which will have a code query parameter appended to it. You’ll use that code and the client secret to get an access_token and refresh_token from HubSpot.
https://app.hubspot.com/oauth/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&scope=contacts%20automation&redirect_uri=https://www.example.com/
https://app.hubspot.com/oauth/123456/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&scope=contacts%20automation&redirect_uri=https://www.example.com/
https://example.com/?code=xxxx
https://www.example.com/?error=error_code&error_description=Human%20readable%20description%20of%20the%20error
access_token
to authenticate any API calls made for that HubSpot account.
access_token
expires, use the refresh_token
to generate a new access_token
.
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.Parameter | Description | How to use |
---|---|---|
client_id | An ID that serves as a unique identifier for your app. | Get this from your app’s Auth settings page (as described above). |
redirect_uri | The URL visitors will be redirected to after granting access to your app. | You’ll also designate this on your app’s Auth settings page. Note: For security reasons, this URL must use https in production. (When testing using localhost , http can be used.) You also must use a domain, as IP addresses are not supported. |
scope | A space-separated set of permissions that your app needs access to. | Any scopes that you’ve checked off in your app’s Auth settings will be treated as required, and you’ll need to include them in this parameter or the authorization page will display an error. Additionally, users will get an error if they try to install your app in an account that doesn’t have access to an included scope. Consult the scopes reference documentation for more details about which endpoints can be accessed by specific scopes. |
Parameter | How to use | Description |
---|---|---|
optional_scope | A space-separated set of optional permissions for your app. | Optional scopes will be automatically dropped from the authorization request if the user selects a HubSpot account that doesn’t have access to that tool (e.g., authorizing a Content Hub Enterprise scope in a HubSpot free account). If you’re using optional scopes, you will need to check the access token or refresh token to see which ones were granted. Check out the reference documentation on scopes for more details. |
state | If this parameter is included in the authorization URL, the value will be included in a state query parameter when the user is directed to the redirect_uri . | A string value that can be used to maintain the user’s state when they’re redirected back to your app. |
optional_scope
parameter to include any tiered scopes you work. This way, customers using HubSpot free accounts can still authorize your app, even if they can’t access all of its scopes. Your app must check for and handle any scopes that it doesn’t get authorized for.
A full list of scopes is available here.