# HighLevel

Status on 2026-11-25: implemented locally and covered by mocked contract tests in `tests/highlevel.spec.ts`. No HighLevel sub-account, private integration token or Zernio HighLevel connection has been used. Nothing here is live-tested.

This is a small integration on purpose. It sends contacts from one Hyperchat workspace to one HighLevel sub-account (location). It is not a two-way sync.

## What it does

- An owner or admin connects one sub-account per workspace under Settings, HighLevel.
- Test connection makes read-only requests and reports whether HighLevel answered.
- Send to HighLevel, on a saved contact, looks the person up by email and then by phone. It updates the contact it finds, or creates one when there is none. It never creates a contact when a match was found.
- Two switches, both off by default, send new contacts and funnel leads automatically.
- An optional tag is added to each contact sent with a private integration token.
- Recent sends lists the last 30 pushes with their outcome.

## What it does not do

These are out of scope and there is no partial version of them:

- Opportunities and pipelines.
- Bringing contacts in from HighLevel, or any update from HighLevel back to Hyperchat.
- Workflows and automations in HighLevel.
- Syncing conversations or messages.
- Custom fields, notes, tasks, appointments and Do Not Disturb settings.
- Removing tags, deleting contacts or merging duplicates.
- More than one sub-account per workspace, or an agency-wide connection.

Only name, email, phone and company are sent. Hyperchat tags and custom fields stay in Hyperchat.

## Two ways to connect

### Through Zernio

Needs the deployment's Zernio key and a Zernio profile assigned to the workspace. The admin chooses Connect HighLevel, approves the install on HighLevel's screen and comes back to Settings. Hyperchat then asks Zernio which active HighLevel accounts belong to this workspace's profile and stores the account id. The account id in the return link is only a hint: it is used when Zernio lists it for this profile, and ignored otherwise. With several sub-accounts on one profile the admin picks one.

Read this before choosing Zernio. A HighLevel account connected in Zernio starts with Zernio's own features on by default: matching and creating contacts from inbox conversations, logging inbox messages as notes, creating contacts from ad leads, mirroring some conversations and relaying conversions. That is Zernio's behaviour, set in Zernio, and Hyperchat neither changes nor depends on it. Test connection lists the ones that are on. If you want only what this page describes, use a private integration token.

The configured tag is not added in this mode. Zernio's CRM contact schema documents no tag field.

### Private integration token

1. In the HighLevel sub-account open Settings, Private Integrations and create an integration.
2. Select the `contacts.readonly` and `contacts.write` scopes. `locations.readonly` is optional and only lets Test connection show the sub-account's name.
3. Copy the token. HighLevel shows it once.
4. In Hyperchat open Settings, HighLevel. Paste the token and the sub-account's location ID, then choose Save token and Test connection.

The token is stored in the `highlevelConnections` table and is never returned to the browser. The settings screen shows that it is connected and the last four characters. HighLevel recommends rotating these tokens every 90 days; save the new token the same way.

A token created at agency level is not expected to work. The contact endpoints ask for a sub-account token.

## Rules a push follows

- **Find first.** A contact that was sent before is updated by its saved HighLevel id. Otherwise Hyperchat looks it up by email, then by phone, and updates the match.
- **Create safely.** With no match, the token mode uses HighLevel's upsert endpoint, which applies the sub-account's own duplicate setting, so a contact that appeared a moment earlier is matched rather than duplicated. In Zernio mode a duplicate that HighLevel refuses is linked to the contact it names and left unchanged.
- **Needs an identity.** A contact with no email and no phone in international format (`+15551234567`) is not sent. A phone in another format is left out with a note.
- **Tags are added, not replaced.** The tag goes through HighLevel's add-tag endpoint. Sending tags on the contact itself would overwrite the contact's existing tags, so that is never done.
- **Company is create-only in token mode.** HighLevel's documented update body has no company field.
- **Blank values do not clear anything.** Only filled fields are sent.
- **Unknown results are held.** A timeout, a dropped connection, an HTTP 5xx or 408, or an unreadable success reply after a write is recorded as "Unknown, check HighLevel". It is never retried automatically, and it blocks automatic sends for that contact. A person can choose Send again after checking; that attempt looks the contact up first, so a create that did land is updated.
- **Clear failures can be sent again.** A rejection (4xx) changed nothing and is shown as not sent, with HighLevel's reason.
- **A missing linked contact is forgotten.** If HighLevel answers 404 for a saved id, the link is removed and the next send looks the person up again.

### Automatic sending

- New contacts: when a contact is created in the workspace, by a person, the API, a Seedly import or a form. Editing an existing contact does not send it.
- Funnel leads: each accepted funnel form, whether the contact is new or returning. Archived contacts are skipped.
- Contacts created from a social conversation usually have no email or phone yet, so they are not sent automatically. Add one and use Send to HighLevel.
- Ad leads count as new contacts when they create one. There is no separate switch for them.
- Automatic work is dispatched by a one-minute tick, ten contacts at a time. Manual sends start at once.
- A failed connection test switches both automatic options off.

## Functions

| Function | Who | Purpose |
| --- | --- | --- |
| `highlevel:status` | owner, admin | Connection summary without the token |
| `highlevel:saveToken` | owner, admin | Store a token and location ID |
| `highlevelWorkers:connectUrl` | owner, admin | Start the Zernio install |
| `highlevelWorkers:finishZernio` | owner, admin | Confirm and store the Zernio account |
| `highlevelWorkers:test` | owner, admin | Read-only connection test |
| `highlevel:updateSettings` | owner, admin | Automatic switches and tag |
| `highlevel:disconnect` | owner, admin | Remove the connection and token |
| `highlevel:activity` | owner, admin | Last 30 pushes |
| `highlevel:send` | owner, admin, agent | Queue one contact |
| `highlevel:contactStatus` | owner, admin, agent | Last result for one contact |

Internal: `highlevel:claim`, `highlevel:finish`, `highlevel:tick` (minute cron), `highlevelWorkers:push`, and `queueHighLevel` in `convex/highlevelQueue.ts`, which `writeContact` and the funnel form call.

Tables are defined in `convex/highlevelModel.ts`: `highlevelConnections`, `highlevelJobs`, and `highlevelLinks`, which holds the remote contact id per workspace and contact. The `contacts` table has no HighLevel fields.

Disconnecting in Hyperchat removes the stored token or account id. In Zernio mode the sub-account stays connected in Zernio until it is removed there.

## Provider documentation

Checked on 2026-11-25.

HighLevel, all with `Authorization: Bearer <token>` and `Version: v3` against `https://services.leadconnectorhq.com`:

- [Get duplicate contact](https://marketplace.gohighlevel.com/docs/ghl/contacts/get-duplicate-contact/index.html): `GET /contacts/search/duplicate?locationId=&email=` or `&number=`
- [Upsert contact](https://marketplace.gohighlevel.com/docs/ghl/contacts/upsert-contact/index.html): `POST /contacts/upsert`
- [Update contact](https://marketplace.gohighlevel.com/docs/ghl/contacts/update-contact/index.html): `PUT /contacts/{contactId}`
- [Add tags](https://marketplace.gohighlevel.com/docs/ghl/contacts/add-tags/index.html): `POST /contacts/{contactId}/tags`
- [Get sub-account](https://marketplace.gohighlevel.com/docs/ghl/locations/get-location/index.html): `GET /locations/{locationId}`
- [API versioning](https://marketplace.gohighlevel.com/docs/Versioning/): `v3` was released on June 11, 2026; the dated versions are still listed as supported
- [Private integrations token](https://marketplace.gohighlevel.com/docs/Authorization/PrivateIntegrationsToken/index.html) and the help article [Private integrations: everything you need to know](https://help.gohighlevel.com/support/solutions/articles/155000003054-private-integrations-everything-you-need-to-know)

Zernio, from its OpenAPI document: `GET /v1/connect/gohighlevel`, `GET /v1/accounts`, `GET /v1/accounts/{accountId}/gohighlevel-settings`, `GET /v1/crm/{accountId}/contacts/search`, `POST /v1/crm/{accountId}/contacts`, `PATCH /v1/crm/{accountId}/contacts/{contactId}`.

## Not confirmed from documentation

1. The private integration page still shows `Version: 2021-07-28` in its examples while each contact endpoint page says to send `v3`. The code sends `v3`. Change `HIGHLEVEL_API_VERSION` in `convex/highlevelProvider.ts` if a real sub-account refuses it.
2. HighLevel's contact pages list only success responses. Error bodies are read as `{ message }` where `message` is text or a list, which is HighLevel's usual shape but is not on those pages.
3. Whether the duplicate lookup sees a contact created seconds earlier. If it lags, Send again after an unknown result could create a second contact in a sub-account that allows duplicates. Upsert reduces this, and the app asks the person to check HighLevel first.
4. The scope labels in HighLevel's screen, and where the location ID is displayed. The docs name the scopes `contacts.readonly` and `contacts.write` and use a 20-character id.
5. Whether an agency-level token can reach contacts. The endpoint pages say "Token type: Sub-Account Token".
6. The host of HighLevel's install screen. The app accepts an authorization link only on `gohighlevel.com`, `leadconnectorhq.com` or `zernio.com`. A white-label install host would be refused and needs adding in `zernioConnectUrl`.
7. Zernio's `properties.source` on create. The schema says a HighLevel record field such as `source` is accepted there.
8. Whether Zernio's return link carries `connected=gohighlevel` and `accountId` exactly as documented. Finish connecting works without them.
9. HighLevel's rate limits were not re-read. Automatic sends are paced at ten contacts a minute, at most four requests each. A 429 is shown as not sent.
