# HubSpot

To connect HubSpot with Middle, you'll need to create either a public or private app in HubSpot to facilitate the connection.

## Public App

For detailed guidance on creating a public developer app, refer to HubSpot's [developer documentation](https://developers.hubspot.com/docs/api/creating-an-app). You can also follow the Middle-specific instructions provided below.

### Create a HubSpot developer account

If you don't already have one, you will need to [create a Hubspot developer account](https://app.hubspot.com/signup/developers?_ga=2.262481166.366427625.1677627239-550539865.1675447209).

### Create a new app

1. In your developer account, navigate to **Apps** in the main navigation bar.
2. In the upper right, click **Create app**.
3. Fill in the **App Info** with an app name and description.
4. Go to the **Auth** tab.
5. Scroll down to **Redirect URLs**.
6. Enter the following URL, replacing `{ENTER YOUR INSTANCE NAME HERE}` with your instance name: `{ENTER YOUR INSTANCE NAME HERE}.middle.app/oauth-redirect-uri/`.
7. Scroll down to **Scopes**.
8. Set `oauth` scope as required and the following scopes as conditional:
   * `crm.import`
   * `crm.objects.contacts.read`
   * `crm.objects.contacts.write`
   * `crm.objects.deals.read`
   * `crm.objects.deals.write`
   * `crm.objects.custom.read`
   * `crm.objects.custom.write`
   * `crm.objects.marketing_events.read`
   * `crm.objects.appointments.read`
   * `crm.objects.appointments.write`
   * `crm.objects.users.read`
   * `automation`
   * `forms`
   * `e-commerce`
   * `tickets`
   * `crm.schemas.custom.read`
   * `crm.schemas.contacts.read`
   * `crm.schemas.contacts.write`
   * `crm.schemas.appointments.write`
   * `crm.schemas.appointments.read`
   * `crm.schemas.deals.write`
   * `crm.schemas.deals.read`
9. Click **Create app**.

### Add app public credentials to Middle

You will need to retrieve the Client ID and Client Secret for your new app from the **Auth**.

Add them to [Keys](/middle-docs/app-development/credential-storage.md) section of your instance's HubSpot app along with your redirect URL. These details need to be added in JSON format. Below is an example:

```json
{"client_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"client_secret": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"redirect_url": "https://{ENTER YOUR INSTANCE NAME HERE}.middle.app/oauth-redirect-uri/"}
```

You should now be all set to authenticate HubSpot in your instance.

## Private app

For more information on how to create a private app, [refer to Hubspots directions](https://developers.hubspot.com/docs/guides/apps/private-apps/overview). Otherwise, follow the instructions below:

1. In your HubSpot account, click the **settings icon** in the main navigation bar.
2. In the left sidebar menu, navigate to **Integrations** > **Private Apps**.
3. Click **Create private app**.
4. On the *Basic Info* tab, configure the details of your app:
   * Enter your app's **name**.
   * Hover over the placeholder logo and click the **upload icon** to upload a square image that will serve as the logo for your app.
   * Enter a **description** for your app.
5. Click the **Scopes** tab.
6. Check off the following scopes:
   * `crm.import`
   * `crm.objects.contacts.read`
   * `crm.objects.contacts.write`
   * `crm.objects.deals.read`
   * `crm.objects.deals.write`
   * `crm.objects.custom.read`
   * `crm.objects.custom.write`
   * `crm.objects.marketing_events.read`
   * `crm.objects.appointments.read`
   * `crm.objects.appointments.write`
   * `crm.objects.users.read`
   * `automation`
   * `forms`
   * `e-commerce`
   * `tickets`
   * `crm.schemas.custom.read`
   * `crm.schemas.contacts.read`
   * `crm.schemas.contacts.write`
   * `crm.schemas.appointments.write`
   * `crm.schemas.appointments.read`
7. Click **Create app** in the top right.
8. In the dialog box, review the info about your app's access token, then click **Continue creating**. Middle will need the `client_secret`.
9. Click to finish creating the app.

### Add private app credentials to Middle

You will need to retrieve the `client_secret` for your private app and enter it to authenticate your Hubspot app connection:

<figure><img src="/files/VmVUe5Ws6wTDuKCT3e2L" alt=""><figcaption><p>Enter your private app token and redirect URL in the Hubspot app connection</p></figcaption></figure>

To complete the connection you will need to click launch an OAuth flow.

{% hint style="info" %}
Your Middle redirect URL will be `https://{your_subdomain}.middle.app/oauth-redirect-uri/`

**For INTEGRATE customers** this is `https://integrate.middle.app/oauth-redirect-uri/`
{% endhint %}

## Syncing contact custom properties

Custom properties can be synced into HubSpot for Contacts. For flexibility, properties are synced as arrays of key/value pairs. There is one array for each data type: strings, numbers, dates, datetimes, and arrays of strings. You can use [array manipulation tools](broken://pages/DDDZXQw14nGMXjdFrHf2#array-manipulation) to integrate these custom properties into your workflow.

### Selecting properties to sync

In your Hubspot connection's [authentication](/middle-docs/app-development/authentication.md), you'll need to list which custom properties you'd like to sync. This is set up to help limit the size of your contact records.

<figure><img src="/files/LN51NN7Qx7juwJLOgVOz" alt=""><figcaption><p>Enter your custom properties one per line</p></figcaption></figure>

On the app connection page, you'll need to enter the internal property name (found in the property manager) under **Custom Fields For Contacts**.&#x20;

<figure><img src="/files/ExjsYAN9j2TqfDHDdGto" alt=""><figcaption><p>Viewing the internal name for a Hubspot property</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.middle.app/middle-docs/guides/app-reference/hubspot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
