# Send conversions to HubSpot

Log every purchase, lead or sign-up from your other sources on the person's HubSpot contact, created by email when it is new.

HubSpot can be an event destination like an ad platform: each conversion a profile receives is logged as a note on the person's contact.

## Before you start

- Connect HubSpot to the profile ([Connect](/platforms/hubspot/connect)). The scopes every connection already grants cover this, so no reconnect is needed.
- Events need the person's unhashed `email`. Events without one are listed in `failures` with code `INVALID_EVENT`.

## Forward conversions to HubSpot

Add a forwarding rule whose `destinationId` is the connection's portal id, as listed by `GET /v1/ads/conversions/destinations`:

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">

```javascript
await fetch('https://zernio.com/api/v1/events/forwarding-rules', {
  method: 'POST',
  headers: { Authorization: `Bearer ${process.env.ZERNIO_API_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({ profileId: 'PROFILE_ID', accountId: 'HUBSPOT_ACCOUNT_ID', destinationId: 'PORTAL_ID', eventNames: ['Purchase', 'Lead'] }),
});
```

</Tab>
<Tab value="Python">

```python
import os, requests

requests.post(
    "https://zernio.com/api/v1/events/forwarding-rules",
    headers={"Authorization": f"Bearer {os.environ['ZERNIO_API_KEY']}"},
    json={"profileId": "PROFILE_ID", "accountId": "HUBSPOT_ACCOUNT_ID", "destinationId": "PORTAL_ID", "eventNames": ["Purchase", "Lead"]},
)
```

</Tab>
<Tab value="curl">

```bash
curl -X POST "https://zernio.com/api/v1/events/forwarding-rules" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "profileId": "PROFILE_ID", "accountId": "HUBSPOT_ACCOUNT_ID", "destinationId": "PORTAL_ID", "eventNames": ["Purchase", "Lead"] }'
```

</Tab>
</Tabs>

In the dashboard, the same rule is **Ads > Conversions > Destinations > HubSpot**.

## How it behaves

- The contact is found by its primary or an additional email. A new one is created with the event's `firstName`, `lastName` and `phone`; an existing contact is never changed, and its lifecycle stage stays as it is.
- The note is titled with the event name and lists the value and currency, the action source, the campaign, the page, the order id and the event id. Its time is the event's `eventTime`.
- Events whose source is HubSpot (closed-won deals, qualified leads) are never sent back to HubSpot, even from a rule that lists every source.
- HubSpot has no test mode: an event sent with `testCode` is not logged (code `TEST_MODE_UNSUPPORTED`).
- Events go in batches of 100 within the portal's API limit. An email HubSpot refuses fails only its event. When HubSpot is down or rate-limits before the note is written, the events are sent again later; a failed note write is not, so a note is never logged twice.

## If it fails

| Error | Cause | Fix |
|---|---|---|
| `This HubSpot connection did not grant …` | The portal installed the app without a scope this needs | Reconnect HubSpot and approve every scope |
| `HubSpot refused this connection's token` | The app was uninstalled or access revoked | Reconnect HubSpot |
| `HubSpot API budget for this connection is spent` | The portal's API limit is reached | Nothing: the batch is sent again later |
| `INVALID_EVENT` | The event has no unhashed email | Send `user.email` |

## Related

- [Add a forwarding rule](/conversions/create-forwarding-rule)
- [Send events](/conversions/send-events)
- [Deals](/platforms/hubspot/deals)