> ## Documentation Index
> Fetch the complete documentation index at: https://docs.1club.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync to a CRM

> Keep Salesforce, HubSpot or your own database in step with a gym's memberships, signed agreements, discounts and attribution.

A gym often wants its sales tool to know what its members hold: which membership, how it was sold, whether it was cancelled and why, what was signed and where the lead came from. 1club gives your integration the same building blocks whatever the tool is: Salesforce through a flow or a middleware, Zapier, Make, or your own code.

The pattern has three steps:

1. **An event says something changed.** A [webhook](https://docs.1club.ai/api-reference/channel-integration/webhooks.md) arrives with the type and the id of the record. It carries ids and statuses, never the record itself.
2. **You read the record.** Call the API with the id, under your own key and scopes.
3. **You write back what your side knows.** A note from a salesperson, or a contact's source, goes back with a write.

Nothing here is specific to one CRM. It is a thin trigger and a read, so your side decides what to store.

## What you can read

| You want | Subscribe to | Read it with |
| - | - | - |
| The membership status | `membership.created`, `membership.activated`, `membership.paused`, `membership.resumed`, `membership.cancelled`, `membership.expired`, `membership.updated` | [`GET /v1/platform/memberships/{id}`](https://docs.1club.ai/api-reference/channel-integration/memberships#get-a-membership) |
| The active primary and personal training memberships, with what they include | `membership.*` | The same read. `planCategoryId` tells a personal training membership from a primary one, and `allowances[].validFor` says what each covers. |
| Past memberships, with the cancellation reason | `membership.cancelled`, and `membership.updated` for one that ends at the end of the period | [`GET /v1/platform/memberships?contactId=...`](https://docs.1club.ai/api-reference/channel-integration/memberships#list-memberships) with no `status`. Each carries `cancellation`, whose `reason` can be `null` when none was given. |
| The discount codes used | `membership.created` | The membership's `promotions`, one entry for each, with the promotion's `code` and how many times it was redeemed. |
| The join channel | `membership.created` | The membership's `source`: `website`, `app`, `portal`, `admin`, and so on. |
| The signed membership agreement | `document.signed` | [`GET /v1/platform/signed-documents/{id}`](https://docs.1club.ai/api-reference/channel-integration/signed-documents) for the record, `?membershipId=` to find a membership's contract, and `/pdf` for a copy. Needs `signed-documents:read`. |
| Click ids and campaign tags | `contact.created`, then `membership.created` | [`GET /v1/platform/contacts/{id}/marketing-touches`](https://docs.1club.ai/api-reference/channel-integration/contacts#marketing-touches), oldest first. |

## What you can write

| You want to send | Call |
| - | - |
| A sales note onto the member's profile | [`POST /v1/platform/contact-notes`](https://docs.1club.ai/api-reference/channel-integration/contacts#add-a-note). A note from an API key names no author, so it never reads as a colleague's. |
| The contact's source from your CRM | [`PATCH /v1/platform/contacts/{id}`](https://docs.1club.ai/api-reference/channel-integration/contacts#update-a-contact) with `sourceId`. List the sources with `GET /v1/platform/contact-sources`. |

## A worked flow

**1. Create a key**

Under **Settings** > **Integrations** > **APIs & webhooks**, make an API key with `webhooks:write`, `contacts:read`, `contacts:write`, `memberships:read` and `signed-documents:read`. Add `webhooks:read` if you list your own subscriptions. See [Authentication](https://docs.1club.ai/api-reference/channel-integration/authentication.md).

**2. Subscribe**

Create an endpoint for `membership.created`, `membership.cancelled` and `document.signed`. Limit it to some gyms with `clubIds` if the CRM serves only some. See [Manage webhooks over the API](https://docs.1club.ai/api-reference/channel-integration/webhooks.md#manage-webhooks-over-the-api).

**3. Receive and verify**

Check the `1Club-Signature` header against the raw body, then answer `2xx` quickly. Store the event `id` so a retry does not run twice.

**4. Read**

On `membership.created`, read the membership, then the contact's marketing touches. On `document.signed`, read the signed document and, if you keep a copy, download its PDF.

**5. Write**

Update your record. Send a salesperson's note back with `POST /v1/platform/contact-notes`.

> [!NOTE]
>
> Read the marketing touches again on the contact's first `membership.created`,
> not only on `contact.created`. A sign-up's touch can be written just after the
> contact event is sent.

A cancellation recorded for the end of the period keeps the membership `active` until then, so it arrives as `membership.updated` (with `cancelsAt` in `changedFields`), not as `membership.cancelled`. Read the membership's `cancellation` on either event.

> [!NOTE]
>
> A contract accepted at online checkout is written before its membership exists,
> so `document.signed` for it is sent when the membership is created, and carries
> the membership and its gym. To fetch a membership's contract yourself, list the
> signed documents with `?membershipId=`.

## Staying correct

Webhooks are delivered at least once and can arrive in any order. Deduplicate on the event `id`, and order one record's events by `sequence`. `document.signed` can also arrive more than once for the same signature in rare cases, such as a birthdate that was mistyped and then corrected, so upsert the signed document by `data.id` instead of adding a row for each event. Events are recorded only while an endpoint subscribes to the type, so after downtime longer than the retry window, list the memberships and signed documents you keep to catch up. See [Delivery, retries, and idempotency](https://docs.1club.ai/api-reference/channel-integration/webhooks.md#delivery-timing).

## What stays out of this API

* **The salesperson.** A member's assigned staff member is not part of the sync. Agree with the gym what "salesperson" means before building on it.
* **Payments.** Reading and writing payments is a separate set of endpoints.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.