---
title: "Connect your own backend with a custom connection"
description: "Recognize your subscribers from your own system, such as a CRM RightMessage has no integration for, and send their answers back to it."
canonical: "https://rightmessage.com/help/custom-connections"
last-updated: 2026-12-03
---

# Connect your own backend with a custom connection

Recognize your subscribers from your own system, such as a CRM RightMessage has no integration for, and send their answers back to it.

A custom connection lets RightMessage recognize your subscribers from a system it has no integration for: a CRM on your own server, a membership site, a newsletter tool with an API, or your own database. Once it's set up, visitors who click a link in your emails (or who are signed in to your site) are recognized, their segments and fields come from your system, and the answers they give on your site can be written back to it.

You don't need an email platform connected to use one, and you can have one alongside an email platform. Projects without a custom connection aren't affected at all: nothing extra loads on their pages.

> **Note**
>
> This guide is for whoever builds the backend side. If you want an AI coding agent to build it for you, give it [Build a custom connection with an AI agent](https://rightmessage.com/help/build-a-custom-connection-with-an-ai-agent) instead. It has everything the agent needs in one place.

## How it works

A custom connection has two halves:

- **In RightMessage**, a connection record with a name, an ID (such as `fluentcrm`), a signing secret, the link parameters your emails use, and optionally the URL of your backend.
- **On your side**, a small backend that answers two signed requests: `/resolve` (who is this subscriber?) and `/changes` (save these answers). A [Cloudflare Worker](#use-the-cloudflare-worker-template) is the easiest way to run one.

There are three ways a visitor gets recognized:

| Way                             | When to use it                                                                          | Trust    |
| ------------------------------- | --------------------------------------------------------------------------------------- | -------- |
| **Link token** (`?fc_hash=…`)   | Links in your emails. Your backend turns the token into a subscriber.                   | Signed   |
| **Signed identify**             | Pages where the visitor is signed in to your site. Your server prints a signed snippet. | Signed   |
| **Link ID** (`?roost_id=48213`) | Quick tests only. Anyone can change the number in a link.                               | Declared |

A **signed** identity is one RightMessage checked with your secret. Only signed identities get data from your backend and write answers back to it. A **declared** identity still applies its segments on the page, exactly as if you'd called `addSegment` yourself, but it never reads or writes your backend.

## Create the connection

1. Go to **Settings › Integrations**. On the **Email platform** tab, find **Custom connections** below your email platform.
2. Click **New connection**.
3. Fill in the form:
   - **Name**: what you'll call it, such as `FluentCRM`.
   - **Connection ID**: lowercase letters, numbers and dashes, such as `fluentcrm`. It can't be changed later, and your backend and snippets use it.
   - **Link parameter** (optional): a URL parameter that carries a subscriber ID. Use it only for testing; link IDs stay declared.
   - **Link token parameter** (optional): a URL parameter that carries a token your backend can turn into a subscriber, such as `fc_hash`.
   - **Backend URL** (optional): your backend's `https://` address. You can only set it here, when you create the connection, so deploy your backend first (it can answer with errors until it has the secret). Leave it empty if you only use signed identify.
4. Click **Create connection**.
5. Copy the **signing secret** from the notice that appears and store it on your server, for example as a Worker secret. It's shown only once. Click **Done** when you've stored it.

Your project's live tag updates as soon as the connection exists; you don't need to publish.

## Recognize visitors from your email links

Add the link token parameter to the links in your emails, filled with a merge tag that gives each subscriber their own token. For FluentCRM that's the subscriber hash:

```text
https://yoursite.com/pricing?fc_hash={{contact.hash}}
```

When a visitor arrives with a token, RightMessage asks your backend's `/resolve` who it belongs to. If your backend finds them, the visitor is recognized as signed, and the segments and fields your backend returned apply on the page.

Use a token your system can look up and nobody can guess, such as a random per-subscriber hash. Don't use a plain email address or a sequential ID: anyone could change it to someone else's. A token must be 16 to 256 characters of letters, digits, `.`, `_`, `~` and `-`; RightMessage ignores anything else without asking your backend.

Send yourself a test email first to check the merge tag prints a token. If it prints nothing, or the tag itself, nobody is recognized.

## Recognize signed-in visitors

On pages where the visitor is signed in to your site, print a signed `identify` from your server:

```html
<script>
  window.RM = window.RM || [];
  RM.push(['identify', {
    connection: 'fluentcrm',
    externalId: '48213',            // the subscriber's ID in your system
    segments: ['seg_pro'],          // optional segment IDs
    fields: { plan: 'pro' },        // optional, readable as {{ connection.fields.plan }}
    ts: 1764700000,                 // Unix seconds, when you signed it
    signature: '…'                  // see "Sign an identify" below
  }]);
</script>
```

The segments apply at once, and RightMessage checks the signature in the background, so the page never waits. A claim is valid for 5 minutes, so render it on each request. Never put it in cached HTML: the cache would show one subscriber's claim to everyone.

### Sign an identify

1. Build a JSON object with `connection`, `externalId`, `pid` (your project ID, as a string), `ts`, and any of `email`, `segments` and `fields` you send. Leave out optional keys you don't send, and any that are `null` or empty (`[]`, `{}`). `externalId` must be a JSON string, even when your IDs are numbers.
2. Serialize it with keys sorted at every level and no whitespace, escaping strings the way JavaScript's `JSON.stringify` does.
3. Compute HMAC-SHA256 with your signing secret over `rm-claim.v1` followed by a newline and that JSON. Send it as lowercase hex.

`fields` values can be strings, integers, booleans or `null`. Field keys match `[A-Za-z_][A-Za-z0-9_.-]{0,63}`. A claim can have at most 50 fields.

Test vector, with the test secret `rm-test-secret-0123456789abcdefghijklmnopqrstuv` and project ID `1213277114`:

|                |                                                                                                            |
| -------------- | ---------------------------------------------------------------------------------------------------------- |
| Claim          | `{"connection":"roost","externalId":"48213","ts":1764700000}`                                              |
| Signed message | `rm-claim.v1` + newline + `{"connection":"roost","externalId":"48213","pid":"1213277114","ts":1764700000}` |
| Signature      | `8eed1ad09fdd409498a30c6c8cae33d7db51bc033f23be8612a86bbe8412f26d`                                         |

During a secret rotation, also send `kid` with the key ID of the secret you signed with.

## Build the backend

Your backend answers two `POST` requests at your backend URL: `/resolve` and `/changes`. Both have JSON bodies, and every request and every response is signed.

### `/resolve`: look up a subscriber

RightMessage sends:

```json
{ "pid": "1213277114", "connection": "fluentcrm", "clues": { "token": "…" } }
```

`clues` holds either `externalId` (with `email` too when RightMessage knows it) or `token`. Look the subscriber up by `externalId` when it's there. Answer:

```json
{ "found": true, "contact": { "externalId": "48213", "email": "pat@example.com", "segments": ["seg_pro"], "fields": { "plan": "pro" } } }
```

or `{ "found": false }`. `segments` are RightMessage segment IDs; `fields` follow the same rules as in a signed identify. RightMessage uses a profile only when its `externalId` is the subscriber it asked about.

RightMessage waits at most **800 ms** for `/resolve` (300 ms to connect). It caches each answer for 5 minutes and, when your backend is down, keeps using a cached answer for up to 24 hours. After 5 failures in a row it stops asking for 60 seconds. A slow or failing backend never slows the page; the visitor just isn't enriched.

### `/changes`: save answers

When a signed visitor answers a question or a script calls `addSegment`/`removeSegment`, RightMessage queues the change and sends it:

```json
{
  "pid": "1213277114",
  "connection": "fluentcrm",
  "changes": [
    { "id": "chg_3f1c…", "externalId": "48213", "op": "segment.add", "segmentId": "seg_topic_seo", "cause": "answer", "at": 1764700000 }
  ]
}
```

`op` is `segment.add` or `segment.remove`. Answer with a result for each change:

```json
{ "results": [ { "id": "chg_3f1c…", "status": "applied" } ] }
```

- `applied`: done.
- `rejected`: you won't apply it. RightMessage won't send it again.
- `retry`: try later. A change missing from `results` counts as `retry`.

`id` is an idempotency key: apply each `id` at most once, because RightMessage may send the same change again after a timeout or a `retry`. It tries each change up to 5 times over at most 24 hours, then gives up on it.

> **Warning**
>
> **Only write segments you allow-list.** A visitor decides what `/changes` asks for: their answers and `RM.push(['addSegment', …])` can put them in any segment. Your backend must accept only segments that are safe for a visitor to choose, such as interests and preferences, and answer `rejected` for everything else. Never let `/changes` grant access, mark a purchase, or change a plan.

RightMessage sends changes in batches of up to 10, waits up to 5 seconds, and retries with backoff. Per subscriber, at most 50 changes wait at once and 500 are accepted a day. Changes only flow for signed visitors.

### Verify every request

Each request carries these headers:

| Header              | Value                                   |
| ------------------- | --------------------------------------- |
| `RM-Key-Id`         | The key ID of the secret that signed it |
| `RM-Timestamp`      | Unix seconds                            |
| `RM-Nonce`          | 32 random hex characters                |
| `RM-Content-SHA256` | Hex SHA-256 of the raw body             |
| `RM-Signature`      | `v1=` followed by the hex HMAC-SHA256   |

The signature covers these lines, joined with a newline: `rm-request.v1`, the method (`POST`), the URL path (such as `/resolve`, without host or query), your project ID, your connection ID, the timestamp, the nonce, and the body's SHA-256.

Reject a request (401) when:

- the timestamp is more than 300 seconds from your clock;
- you've seen its nonce in the last 10 minutes;
- the body's SHA-256 doesn't match `RM-Content-SHA256`;
- the signature doesn't match, compared in constant time;
- the body's `pid` or `connection` isn't yours (403).

During a rotation, accept a signature made with either your current or your previous secret.

### Sign every response

Every response, errors included, carries `RM-Signature: v1=<hex>`, an HMAC-SHA256 with the same secret over these lines joined with a newline: `rm-response.v1`, the request's nonce, the HTTP status, and the SHA-256 of your response body. RightMessage throws away any response that isn't signed this way.

Respond with `Content-Type: application/json`, keep responses under 64 KB, and don't redirect: RightMessage doesn't follow redirects.

### Your backend URL

RightMessage only calls `https://` URLs on port 443 or 8443, on a public hostname (not an IP address or a private name such as `.local`), with no username, password, query or fragment. It checks the address again before every call.

## Use the Cloudflare Worker template

The quickest backend is a Cloudflare Worker. The template does all the signing for you and comes with adapters:

- **FluentCRM** (WordPress) over its REST API, with a WordPress Application Password. It finds subscribers by ID or email and can save interest tags, but it can't look up link tokens.
- **SQL** through Cloudflare Hyperdrive, one parameterized query against your database. It's the adapter that looks up link tokens. It's read-only: it answers every change with `rejected`.
- A **subscriber API** example with a bearer token, to adapt to your own system.

[Build a custom connection with an AI agent](https://rightmessage.com/help/build-a-custom-connection-with-an-ai-agent) contains the complete template code and deploy steps.

### Example: FluentCRM with Amazon SES

Amazon SES only sends FluentCRM's email; RightMessage never touches it.

Pick the Worker's entry point first:

- To recognize visitors who click links in your FluentCRM emails, use the SQL entry point (`src/index-sql.js`). It reads FluentCRM's tables through Hyperdrive and looks up each subscriber's hash. It's read-only.
- To recognize signed-in visitors with a signed identify and save their interest tags back to FluentCRM, use the REST entry point (`src/index.js`).

Then:

1. For the REST entry point, create a FluentCRM manager in WordPress with **Contacts Read** and **Contacts Add/Update** only, not an Administrator, and create an Application Password for that user. For the SQL entry point, give Hyperdrive a database user that can only read the FluentCRM tables.
2. Deploy the Worker with your project ID, the connection ID `fluentcrm`, your FluentCRM URL or Hyperdrive binding, and which FluentCRM tags map to which segments (with the REST entry point, mark only interest tags writable). Until it has the secret, it answers every request with an error.
3. In RightMessage, create a connection named `FluentCRM` with the ID `fluentcrm`, the Worker's URL as its **Backend URL** and, for the SQL entry point, the link token parameter `fc_hash`. Copy the secret.
4. Store the RightMessage secret as the Worker secret `RM_CONNECTION_SECRET`, plus the Application Password for the REST entry point.
5. For the SQL entry point, add `?fc_hash={{contact.hash}}` to the links in your FluentCRM emails, and check it in a test email.

## Rotate or revoke the secret

- **Rotate**: click **Rotate secret**. You get a new secret. Put it on your backend right away: from that moment RightMessage signs its `/resolve` and `/changes` calls with the new secret, and a backend that only has the old one fails them. The old secret keeps verifying identify claims your own server signs for 7 days, so you have that long to update the code that signs them. In the Worker, set the new secret as `RM_CONNECTION_SECRET` and the old one as `RM_CONNECTION_SECRET_PREVIOUS`, then remove the old one after 7 days.
- **Revoke**: while a rotation's old key is still active, click **Revoke** followed by its key ID to end it before the 7 days are up. Claims signed with it stop verifying at once, and write sessions it vouched for end. A browser that already verified a claim may keep that result for up to an hour.

## React to changes in the browser

Projects with a custom connection also get the `rm:visitor:change` event on `document`, and an `onSync` callback you can pass to `identify`. They fire when the visitor's segments, connection fields or identity change. `onSync` gets the same payload, except for the changes your own `identify` made.

```javascript
document.addEventListener('rm:visitor:change', (event) => {
  const { changed, cause, connection, visitorId } = event.detail
  // cause: 'identify', 'api' (addSegment, removeSegment, clearAnswers, clearAllData), 'answer' or 'signal'
  // changed.segments.added / changed.segments.removed: segment IDs
  // changed.fields: { key: newValue } for connection fields that changed (null when removed)
  // changed.identity: { connection, externalId, trust } when the identity or its trust changed, else null
})
```

Changes arrive once per tick, one event per cause. The first page a visitor sees reports every segment they're in as added; later pages report only differences. The event isn't sent in the debugger or a dashboard preview, and it waits for consent where consent is required. For other browser commands, see [Browser JavaScript commands and events](https://rightmessage.com/help/javascript-hooks).

This runs in the page, so it's best effort. Use `/changes` when you need every answer saved.

## Test it

- Open your site with `?debug=true` and use the debugger. It shows who the visitor is ("subscriber 48213 from FluentCRM"), whether they're signed or declared, and the segments your backend gave them. In the debugger, writes to `/changes` are recorded, not sent.
- Use `{{ connection.fields.plan }}` in a phrase to check that fields arrive.

## Limits

- `claims/verify`: 30 a minute and 300 an hour per visitor network, 1,200 a minute per project.
- Link token lookups: 30 a minute and 300 an hour per visitor network, 120 a minute per project. A visitor network gets 10 tokens your backend didn't recognize an hour. After 300 tokens your backend didn't recognize in an hour, RightMessage stops asking your backend for the rest of that hour, so link tokens are not recognized until the hour is up.
- `/changes` from the page: 10 posts a minute per subscriber, at most 20 changes per post.
- A write session lasts 24 hours.

## Troubleshooting

| You see                                            | Check                                                                                                                                                                                                                                                                             |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The visitor stays **declared**                     | The secret on your server matches the latest one; `ts` is current Unix seconds; the claim isn't from cached HTML; you included `pid` when signing.                                                                                                                                |
| Signed, but no segments or fields from the backend | The backend URL is saved; your `/resolve` signs its response; it answers within 800 ms; `contact.externalId` matches.                                                                                                                                                             |
| Changes never arrive                               | The visitor is signed; your `/changes` returns a `results` entry per `id`; segments you accept are in your allow-list and in your published config.                                                                                                                               |
| A link token isn't recognized                      | The parameter name matches the connection's link token parameter exactly; the token is 16 to 256 characters of letters, digits, `.`, `_`, `~` and `-`; the merge tag printed a token in a test email; your `/resolve` handles `clues.token` (the FluentCRM REST adapter doesn't). |
