# HubSpot

> Turning HubSpot on in Ready-made integrations with a Private App token and six scopes. Creates or updates the contact by e-mail, records the purchase and the renewal as a won deal without duplicates, marks the subscription status and receives form submissions without overwriting contacts.

HubSpot receives members as **contacts** and sales as **won deals**: *"Creates or updates the contact in HubSpot and records purchases and renewals as won deals."*

*Role: owner and admin.* How to turn on, test, disable and remove any app is in [Ready-made integrations](/integracoes/integracoes-prontas).

## 1. Create the Private App in HubSpot

You need to be a super admin of the HubSpot account.

1. In HubSpot, open **Settings** › **Integrations** › **Private Apps** and click **Create a private app**.
2. Give it a name (*Memberfy*).
3. On the **Scopes** tab, check all six:

| Scope | What for |
|---|---|
| `crm.objects.contacts.read` | Find the contact by e-mail |
| `crm.objects.contacts.write` | Create and update the contact |
| `crm.objects.deals.read` | Find the deal of an event already recorded |
| `crm.objects.deals.write` | Create the deal and associate it with the contact |
| `crm.schemas.contacts.write` | Create the subscription status property on the contact |
| `crm.schemas.deals.write` | Create the property that prevents duplicate deals |

4. Click **Create app** and copy the **access token**. It starts with `pat-`.

Memberfy's screen also lists the scopes under **Required scopes**.

## 2. Turn it on in Memberfy

1. In **Settings › Integrations and APIs › Integrations**, click **HubSpot**.
2. Paste it into **Private App token**.
3. Choose the events and check **This app will receive: …**.
4. Click **Turn on** and then **Send test**. The test only checks the token: it creates no contact.

## What arrives

The contact is identified by **e-mail**.

| Event | In HubSpot |
|---|---|
| A member joined the community | Creates the contact (first name, last name, e-mail and phone) or updates the name and phone of the existing one |
| A purchase was completed | A **won** deal *Purchase: {product}*, with the amount paid, in the default pipeline, associated with the contact; the contact's subscription status becomes `active` |
| A subscription was renewed | A won deal *Renewal: {product}*, the same way |
| A subscription was canceled | The contact's subscription status becomes `canceled` |
| A form was submitted | Creates the contact with the name, e-mail, phone, company and job title from the [form](/espacos/formularios) and, when the person agreed, records the consent. For a contact that already exists, see below |

- **No duplicates:** each deal keeps the event that created it (the *Memberfy event id* property). A retry or a **Resend** finds the deal already created and does not create another.
- Both properties, *Memberfy subscription status* (on the contact) and *Memberfy event id* (on the deal), are created automatically the first time.
- **Phone:** goes in international format (`+5541999998888`) when the member added one. On the other events it only goes into a contact created right then; what HubSpot already holds is not overwritten.
- The deal name goes out in the community's language.
- When HubSpot asks to wait (rate limit), the delivery waits and tries again, without counting as a failure.

### Form submissions

- **A visitor never changes an existing contact.** Anyone can type someone else's e-mail into an open form. So a visitor's submission (or a member's with another e-mail) to an existing contact becomes only a **note** on the contact, with what was submitted.
- **A signed-in member's submission with their own profile e-mail** fills in the contact's empty properties (name, phone, company, job title) and records the consent. With **Forms update existing contacts** on, it also updates the ones already filled in.
- **Turned HubSpot on before?** The installation doesn't get the event on its own: open HubSpot in **Integrations**, check **A form was submitted** and save. A new installation already comes with it.

## Common problems

- **"The provider refused the credentials."** The token was changed or the Private App was deleted. Paste the new token and save.
- **Deliveries fail with 403.** One of the six scopes is missing. Edit the Private App in HubSpot, check what is missing and test again.
- **The app became Failing.** See [Turned off after failures](/integracoes/integracoes-prontas#turned-off-after-failures).

## Related

- [Ready-made integrations](/integracoes/integracoes-prontas)
- [RD Station](/integracoes/rd-station)
