# Setting up a Hubspot connector

### Configuring a Hubspot connection

{% hint style="info" %}
Warning

This connector is deprecated. It is recommented to use the **HubSpot connector with Private Apps** instead.
{% endhint %}

<details>

<summary>Create hubspot application</summary>

This connector is used to retrieve data from the HubSpot API: [HubSpot API Documentation](https://developers.hubspot.com/docs/api/overview)

The email events part relies for now on Hubspot’s legacy API: [HubSpot legacy API Documentation](https://legacydocs.hubspot.com/docs/overview)

**Create a HubSpot application¶**

First, you need to create a HubSpot application. To do so, you will need a registered [HubSpot developer account](https://developers.hubspot.com/):

* Head over to `Manage apps`.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-1e5e7342b219adf5b0648b88cd45719347a6f38a%2FDocumentation_HubSpot_manage_apps.png?alt=media" alt="Hubspot Developer Console"><figcaption><p>Hubpot Manage App Menu</p></figcaption></figure>

* Click on `Create app`.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-2e49124ea4daae712163794a715e1b2b5457188c%2FHubSpot_create_app.png?alt=media" alt="HubSpot_create_app"><figcaption><p>HubSpot_create_app</p></figcaption></figure>

* Once the App Info is filled, click on the `Auth` part, you’ll see the following:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-cf2e6340e60a833db283fbb2b5d3c4847038d3f7%2FHubSpot_auth_app_layout.png?alt=media" alt="HubSpot_auth_app_layout"><figcaption><p>HubSpot_auth_app_layout</p></figcaption></figure>

* Scroll down to the “Redirect URL” part and fill up the redirect URI.
  * The redirect URI should be like the following pattern:

    * `https://api-{your-instance-name}.toucantoco.com/oauth/redirect?type=Hubspot`

    <div align="center"><figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-2c5a92c213edcf8ab6753b4f5486a34b892c6d85%2FHubSpot_app_add_redirect_uri.png?alt=media" alt="HubSpot_app_add_redirect_uri"><figcaption><p>HubSpot_app_add_redirect_uri</p></figcaption></figure></div>
* Scroll down to the `Add a required scope` part:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-e13be325fbf894aff5999098ef8b2de0882544db%2FHubSpot_app_add_scopes.png?alt=media" alt="HubSpot_app_add_scopes"><figcaption><p>HubSpot_app_add_scopes</p></figcaption></figure>

* Then add any combination of the following scopes :
  * contacts
  * content
  * forms
  * business-intelligence
  * e-commerce
* Note that the connector will not work on certain types of data if a scope listed above is not added to the required scopes of your HubSpot application.
* Do not forget to click on the `Save` button at the bottom of the page when all your modifications are finished.

**How to connect¶**

Once your HubSpot application is created, you will need to set-up the `client_id` and `client_secret` credentials of your previously created application.

Look at [Set up OAuth2 credentials for your platform](https://docs.toucantoco.com/concepteur/power-apps-with-data/02-connectors.html#set-up-oauth2-credentials-for-your-platform) for more information.

</details>

{% hint style="info" %}
Once the credentials are set-up, you will need to configure your data provider. All of the pulled data is taken from your HubSpot application, whether it’s about email campaigns, companies, deals, etc.
{% endhint %}

<details>

<summary>Authentication to Hubspot</summary>

A pop-up window will open and look like this, click on the account that you wish to link to your connector:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-5a3a5342474793baff008b0e54e0c95ca1ad0300%2FHubSpot_create_connector_step_4.png?alt=media" alt="HubSpot_create_connector_step_4"><figcaption><p>HubSpot_create_connector_step_4</p></figcaption></figure>

On the next window, all the scopes that are required by the application are displayed; a confirmation is required to link your connector to your hubspot account, just click on `Connect app` to do so:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-7f63e32f793a5262b8defa1613f6aa384781e004%2FHubSpot_create_connector_step_5.png?alt=media" alt="HubSpot_create_connector_step_5"><figcaption><p>HubSpot_create_connector_step_5</p></figcaption></figure>

You will be redirected to your instance with a new popup with two fields: `name` and `Auth Flow ID`. `Auth Flow ID` should be pre-filled and `name` empty.

</details>

| Field                                          | Format / Type | Description                                                                                                                                                                                                                                                                             | Example               |
| ---------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| Name (mandatory)                               | String        | Use it to identify your connection                                                                                                                                                                                                                                                      | *MyHubspotConnection* |
| Auth Flow Id (mandatory)                       | String        | Automatically filled by Hubspot                                                                                                                                                                                                                                                         |                       |
| Retry Policy (optional)                        | Boolean       | <p><em>Boolean</em> allows to configure a retry policy if the connection is flaky.</p><ul><li>max attempts: maximum number of retries before giving up</li><li>max\_delay: in seconds, above the connection is dropped</li><li>wait\_time: time in seconds between each retry</li></ul> |                       |
| Slow Queries' Cache Expiration Time (optional) | Integer       | Slow queries cache expiration time in seconds                                                                                                                                                                                                                                           |                       |

#### Create a dataset from a Hubspot connection

Once the data provider is configured, it is possible to add one (or more!) data source that will provide data for your apps.

The `HubspotDataset` parameter is needed to define the kind of data you want to query in the following list:

* `contacts` (default value)
* `companies`
* `deals`
* `products`
* `web-analytics`
* `email-events`

The `HubspotObjectType` and `parameters` parameters are needed for the `web-analytics` dataset:

* `parameters` is a `dict`-like object that will contain filters that you want to use to filter the resulting data
  * The key must follow this schema: `objectProperty.{property}`, where `property` is a value defined in [HubSpot’s documentation](https://developers.hubspot.com/docs/api/crm/properties)
  * The value can be anything
* `HubspotObjectType` has only one value for now (`contact`) but this may evolve in the future

Once you are all set, just hit `SAVE`

### Configuring a HubSpot (with a private application) connection ¶

This connector is used to retrieve data from the HubSpot API: [HubSpot API Documentation](https://developers.hubspot.com/docs/api/overview)

<details>

<summary>Create a private application</summary>

To create one, follow these steps:

1. Go to the **Settings** page of your HubSpot account (click on the small gear in the top right corner of the page).
2. Head over to the **Account Setup/Private Apps** section.
3. Click on the **Create a private app** button.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-070ebcba494f6698bdd8623ee4da5302e42ea665%2FHubSpot_private_app_private_apps_menu.png?alt=media" alt="HubSpot_private_app_private_apps_menu"><figcaption><p>HubSpot_private_app_private_apps_menu</p></figcaption></figure>

1. Fill out the basic information form.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-1908172824f9f57580449f5c3a97e52005ce9125%2FHubSpot_private_app_basic_info.png?alt=media" alt="HubSpot_private_app_basic_info"><figcaption><p>HubSpot_private_app_basic_info</p></figcaption></figure>

1. Click on the **Scopes** tab. Toucan needs a read access on all CRM objects you want to query. The following objects are supported:
   * `companies`
   * `contacts`
   * `deals`
   * `owners`
   * `quotes`
2. Once you’ve ticked all the scopes you need, click on the “Create app” button.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-c615a8bc9e55ce619bf137aaafe466a8160f2183%2FHubSpot_private_app_scopes.png?alt=media" alt="HubSpot_private_app_scopes"><figcaption><p>HubSpot_private_app_scopes</p></figcaption></figure>

1. You will now need to copy your app’s access token: Click on the **View access token** button, and then on **Copy** in the pop-up.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-2856f3cf4fa59981c563a2ab526d73036c5df669%2FHubSpot_private_app_view_access_token.png?alt=media" alt="HubSpot_private_app_view_access_token"><figcaption><p>HubSpot_private_app_view_access_token</p></figcaption></figure>

</details>

Now that your HubSpot private application is created, you can create a connection

| Field        | Format / Type | Description                                                                          | Example                      |
| ------------ | ------------- | ------------------------------------------------------------------------------------ | ---------------------------- |
| Name         | String        | Use it to identify your connection                                                   | *MyPrivateHubspotConnection* |
| Access token | String        | Access token field previously seen in the configuration (will be stored as a secret) |                              |

## Create a dataset from a Hubspot datasource¶

The `HubspotDataset` parameter is needed to specify the kind of data you want to query. Pick the desired dataset (note that your private app needs to have the right scopes for that), and click on **Validate** (or **Run preview** if you want a preview of your data first).
