# Connect

Install the Zernio app on a HubSpot portal to connect it to a profile, from the dashboard or with the connect API.

## Connect from the dashboard

1. Sign in to [Zernio](https://zernio.com/dashboard/connections) (a free account works) and open **Connections**.
2. Click **Connect an account**, pick the profile, and choose **HubSpot** under **CRM**.
3. In HubSpot, pick the portal and approve the app. It asks to read and write contacts, and optionally to read and update deals, read owners and add workflow actions.
4. Back in Zernio, the portal shows on the profile. Contact sync, message logging and delivery status are on, and the deal settings are off.

The person approving must be a HubSpot user who can install apps on the portal.

## Connect a HubSpot portal

Request the authorization link for a profile, then send the user to `authUrl`:

```bash
curl "https://zernio.com/api/v1/connect/hubspot?profileId=PROFILE_ID&redirect_url=https://example.com/done" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

```json
{ "authUrl": "https://app.hubspot.com/oauth/authorize?client_id=…", "state": "…" }
```

The user picks a portal and approves the app. HubSpot returns them to Zernio, which saves the account and redirects to `redirect_url` (or the dashboard) with `connected=hubspot`, `profileId`, `accountId` and `username` (the portal domain).

## Change what syncs

Change any setting with `PATCH /v1/accounts/{accountId}/hubspot-settings`, or from the HubSpot account's **Settings** on **Connections**:

```bash
curl -X PATCH "https://zernio.com/api/v1/accounts/ACCOUNT_ID/hubspot-settings" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "logMessages": false }'
```

`syncContacts` creates a HubSpot contact for an inbox contact that matches none. `logMessages` writes each message on the contact's timeline. `logDeliveryStatus` keeps each outgoing message's [delivery status](/platforms/hubspot/delivery-status) up to date there.

`contactDefaults` sets values for properties your portal requires on new contacts, for example `{ "lifecyclestage": "lead" }`. While the portal refuses new contacts for a missing required property, the settings show `syncIssue` with the properties it named.

`syncContacts`, `logMessages` and `logDeliveryStatus` start on. `useDealsAsResults` and `reportDeals` start off and need deal access; see [Deals](/platforms/hubspot/deals). Read the current values with `GET /v1/accounts/{accountId}/hubspot-settings`.

## Disconnect or uninstall

- **From Zernio:** on **Connections**, click **Disconnect** on the HubSpot account, or call `DELETE /v1/accounts/{accountId}`. Zernio stops syncing and uninstalls the app from the portal, unless another Zernio profile still uses it.
- **From HubSpot:** in the portal, go to **Settings > Integrations > Connected apps** and uninstall Zernio. The account shows as disconnected in Zernio the next time a message syncs.

Either way, what Zernio already wrote stays in HubSpot: the contacts it created and the messages on their timelines are not deleted.

Nothing new syncs until you connect again, and messages from the gap are not backfilled.

## How it behaves

- A profile holds one portal. Reconnecting the same portal refreshes the account in place and keeps its settings; a different portal starts with the default settings.
- A portal connected before an optional permission existed (deal write and owners, used by the [CRM API](/platforms/hubspot/crm-api)) does not have it. Connect again and approve it; the account id and settings stay.
- Access renews by itself. If the app is uninstalled in HubSpot, the account is marked disconnected the next time a message syncs.
- Disconnecting the account in Zernio uninstalls the app from the portal, unless another Zernio profile still uses that portal.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `hubspot_profile_has_portal` on the redirect | The profile already has a different portal connected | Disconnect it first, or connect this portal to another profile. |
| `hubspot_access_denied` on the redirect | The user declined the app in HubSpot | Start the connect again and approve the app. |
| `hubspot_invalid_state` on the redirect | The link expired or was already used | Request a fresh `authUrl`. |
| `hubspot_auth_failed` on the redirect | HubSpot returned without an authorization code | Start the connect again. |
| `hubspot_connection_failed` on the redirect | HubSpot refused the code exchange, or the portal could not be read | Start the connect again; contact support if it repeats. |
| Deals option locked on the consent screen | A HubSpot admin approved the app without its optional deal permission | In HubSpot, open **Settings > Integrations > Connected Apps > Approved apps > Zernio > Manage access > Data Permissions**, enable deals, save, then connect again. |
| `503` on `GET /v1/connect/hubspot` | HubSpot is not configured on this Zernio environment | Contact support. |

## Related

- [Get HubSpot connect URL](/connect/get-hub-spot-connect-url)
- [Get HubSpot settings](/accounts/get-hub-spot-settings)
- [Update HubSpot settings](/accounts/update-hub-spot-settings)