You can authenticate with Hubspot Marketing to create your own instance of the Hubspot Marketing element through the UI or through APIs. Once authenticated, you can use the element instance to access the different functionality offered by the Hubspot Marketing platform.
Use the UI to authenticate with Hubspot Marketing and create an element instance. Hubspot Marketing authentication follows the typical OAuth 2 framework and you will need to sign in to Hubspot Marketing as part of the process.
When you authenticate through the Cloud Elements UI, you pass different scopes depending on the Cloud Elements version (see below). If you cannot authenticate with the default scopes used by the UI, you can pass specific scopes when authenticating via API.
If you are configuring events, see the Events section.
After successfully authenticating, we give you several options for next steps. Make requests using the API docs associated with the instance, map the instance to a virtual resource, or use it in a formula template.
You can authenticate with Hubspot Marketing in one of two ways: OAuth 2.0 and API Keys. Hubspot Marketing recommends API Keys for prototyping and OAuth 2.0 for production integrations. For more information, review Hubspot Marketing's Authentication Overview. Go to the section that matches your authentication method:
Authenticating through API using OAuth 2.0 is a multi-step process that involves:
Use GET /{page.elementKey}/oauth/url
to request a redirect URL and pass scope to Hubspot. The scope parameter values that you include in the request must match the permissions granted to the authorizing user and their account. Some scopes apply only to Marketing accounts (such as content, reports, social, and automation) while others apply to both Marketing and CRM accounts (such as contacts, timeline, and files). If you include Marketing scopes when authenticating with Hubspot CRM, users will receive a Permissions error if their account does not include Marketing permissions.
To be certain that your users can authenticate, you should pass the specific scopes granted to the users and their account. Review the Hubspot OAuth 2.0 scope documentation for the complete list of scopes.
However, if you do not pass any scopes or pass scope without any values, see the table below for the default scopes passed with the GET /{page.elementKey}/oauth/url
request.
Scope Parameter | Default Scope |
---|---|
Hubspot CRM with no scope parameterex. GET /{page.elementKey}/oauth/url?apiKey=...&apiSecret=...&callbackUrl=... |
contacts, timeline, and files |
Hubspot CRM with a scope parameter with no valueex. GET /hubspotcrm/oauth/url?apiKey=...&apiSecret=...&callbackUrl=...&scope= |
contacts, timeline, files, content, reports, social, automation, forms |
Hubspot Marketing with no scope parameterex. GET /{hubspot}/oauth/url?apiKey=...&apiSecret=...&callbackUrl=... |
contacts, timeline, files, content, reports, social, automation, forms |
Hubspot Marketing with a scope parameter with no valueex. GET /hubspot/oauth/url?apiKey=...&apiSecret=...&callbackUrl=...&scope= |
contacts, timeline, files, content, reports, social, automation, forms |
The examples below include recommended scope values. For Hubspot Marketing Basic account users, we recommend not including the automation scope.
Use the following API call to request a redirect URL where the user can authenticate with the service provider. Replace {keyOrId}
with the element key, hubspot
.
curl -X GET "/elements/{keyOrId}/oauth/url?apiKey=<api_key>&apiSecret=<api_secret>&callbackUrl=<url>&scope=contacts%20timeline%20files%20content%20reports%20social%20automation%20forms"
Query Parameter | Description |
---|---|
apiKey | The key obtained from registering your app with the provider. This is the Client ID that you recorded in API Provider Setup section. |
apiSecret | The secret obtained from registering your app with the provider. This is the Consumer Secret that you recorded in API Provider Setup section. |
callbackUrl | The URL that will receive the code from the vendor to be used to create an element instance. |
scope | A space separated set of Hubspot scopes that your app can access. Scopes listed in this parameter are required for your app, and the user will see an error if they do not have access to any scope that you included. |
curl -X GET \
'https://api.cloud-elements.com/elements/api-v2/elements/hubspot/oauth/url?apiKey=fake_api_key&apiSecret=fake_api_secret&callbackUrl=https://www.mycoolapp.com/auth&state=hubspot&scope=contacts%20timeline%20files%20content%20reports%20social%20automation%20forms' \
Use the oauthUrl
in the response to allow users to authenticate with the vendor.
{
"element": "hubspot",
"oauthUrl": "https://login.hubpot.com/services/oauth2/authorize?response_type=code&client_id=fake_api_key&client_secret=xyz789&scope=full%20refresh_token&redirect_uri=https://www.mycoolapp.com/auth&state=hubspot"
}
Provide the response from the previous step to the users. After they authenticate, Hubspot Marketing provides the following information in the response:
Response Parameter | Description |
---|---|
code | The Authorization Grant Code required by Cloud Elements to retrieve the OAuth access and refresh tokens from the endpoint. |
state | A customizable identifier, typically the element key (hubspot ) . |
error
instead of the code
parameter. In this case, your application can handle the error gracefully.
Use the /instances
endpoint to authenticate with Hubspot Marketing and create an element instance. If you are configuring events, see the Events section.
To create an element instance:
Construct a JSON body as shown below (see Parameters):
{
"element": {
"key": "hubspot"
},
"providerData": {
"code": "<AUTHORIZATION_GRANT_CODE>"
},
"configuration": {
"authentication.type": "oauth2",
"oauth.callback.url": "<CALLBACK_URL>",
"oauth.api.key": "<CONSUMER_KEY>",
"oauth.api.secret": "<CONSUMER_SECRET>",
"create.bulk.properties": "false",
"filter.response.nulls": true
},
"tags": [
"<Add_Your_Tag>"
],
"name": "<INSTANCE_NAME>"
}
Call the following, including the JSON body you constructed in the previous step:
POST /instances
Locate the token
and id
in the response and save them for all future requests using the element instance.
curl -X POST \
https://api.cloud-elements.com/elements/api-v2/instances \
-H 'authorization: User <USER_SECRET>, Organization <ORGANIZATION_SECRET>' \
-H 'content-type: application/json' \
-d '{
"element": {
"key": "hubspot"
},
"providerData": {
"code": "xoz8AFqScK2ngM04kSSM"
},
"configuration": {
"authentication.type": "oauth2",
"oauth.callback.url": "https;//mycoolapp.com",
"oauth.api.key": "xxxxxxxxxxxxxxxxxx",
"oauth.api.secret": "xxxxxxxxxxxxxxxxxxxxxxxx",
"create.bulk.properties": "false",
"filter.response.nulls": true
},
"tags": [
"Docs"
],
"name": "API Instance"
}'
To authenticate using a Hubspot HAPIkey:
Construct a JSON body as shown below (see Parameters):
{
"element": {
"key": "hubspot"
},
"configuration": {
"hubspot.authorization.apikey":"3a9990ff-bf17-40b1-9ce1-e1702e36ab51",
"authentication.type": "apiKey",
"create.bulk.properties": "false",
"filter.response.nulls": true
},
"tags": [
"<Add_Your_Tag>"
],
"name": "<INSTANCE_NAME>"
}
Call the following, including the JSON body you constructed in the previous step:
POST /instances
Locate the token
and id
in the response and save them for all future requests using the element instance.
curl -X POST \
https://api.cloud-elements.com/elements/api-v2/instances \
-H 'authorization: User <USER_SECRET>, Organization <ORGANIZATION_SECRET>' \
-H 'content-type: application/json' \
-d '{
"element": {
"key": "hubspot"
},
"configuration": {
"hubspot.authorization.apikey":"xxxxxxxxxxxxxxxxxxxxxxxx",
"authentication.type": "apiKey",
"create.bulk.properties": "false"
},
"tags": [
"Docs"
],
"name": "API Instance"
}'
API parameters not shown in Cloud Elements are in code formatting
.
Parameter | Description | Data Type |
---|---|---|
key |
The element key. hubspot |
string |
code |
The authorization grant code returned from the API provider in an OAuth2 authentication workflow. | string |
Namename |
The name for the element instance created during authentication. | string |
authentication.type |
Identifies how you are authenticating with Hubspot Marketing. Either oauth2 or apiKey . |
string |
Create Bulk Properties for Migrationcreate.bulk.properties |
Identifies if you want to create custom properties in Hubspot for bulk uploads. | string, must be true (Yes) or false (No) |
oauth.callback.url |
OAuth 2.0 authentication only. The URL where you want to redirect users after they grant access. This is the Callback URL that you noted in the API Provider Setup section. | string |
oauth.api.key |
OAuth 2.0 authentication only. The Client ID from Hubspot Marketing. This is the Client ID that you noted in the API Provider Setup section | string |
oauth.api.secret |
OAuth 2.0 authentication only. The Client Secret from Hubspot Marketing. This is the Client Secret that you noted in the API Provider Setup section | string |
Hubspot API Keyhubspot.authorization.apikey |
API Key authentication only. The hubspot API key that you noted in the API Provider Setup section | string |
tags | Optional. User-defined tags to further identify the instance. | string |
In this example, the instance ID is 58772
and the instance token starts with "ABC/D...". The actual values returned to you will be unique: make sure you save them for future requests to this new instance.
{
"id": 58772,
"name": "API Instance",
"createdDate": "2017-08-01T16:12:43Z",
"token": "ABC/Dxxxxxxxxxxxxxxxxxxxxxxxx/9DROw=",
"element": {
"id": 43,
"name": "Hubspot Marketing",
"hookName": "HubSpot",
"key": "hubspot",
"description": "Add a HubSpot Instance to connect your existing HubSpot account to the Marketing Hub, allowing you to manage accounts, campaigns, contacts, leads etc. across multiple Marketing Elements. You will need your HubSpot account information to add an instance.",
"image": "elements/provider_hubspot.png",
"active": true,
"deleted": false,
"typeOauth": true,
"trialAccount": false,
"configDescription": "If you do not have a HubSpot account, you can create one at <a href=\"http://www.hubspot.com\" target=\"_blank\">HubSpot Signup</a>",
"defaultTransformations": [ ],
"objectMetadata": [ ],
"transformationsEnabled": true,
"bulkDownloadEnabled": true,
"bulkUploadEnabled": true,
"cloneable": false,
"extendable": true,
"beta": false,
"authentication": {
"type": "oauth2"
},
"extended": false,
"hub": "marketing",
"protocolType": "http",
"parameters": [],
"private": false
},
"elementId": 43,
"tags": [
"Docs"
],
"provisionInteractions": [],
"valid": true,
"disabled": false,
"maxCacheSize": 0,
"cacheTimeToLive": 0,
"configuration": { },
"eventsEnabled": false,
"traceLoggingEnabled": false,
"cachingEnabled": false,
"externalAuthentication": "none",
"user": {
"id": 3306
}
}
}