# CRM outbound webhook

When a lead's status changes in HeyMySocial, the CRM can be told. That is the only thing HeyMySocial sends to a CRM: one event, `lead.status_changed`, as a signed `POST` to an address you choose.

## Switch it on

1. Open **Settings**, **Connections** and the CRM connection. It has to be a webhook connection.
2. Under **Send status back**, enter the **Address that receives status changes**.
3. Tick **Send lead status changes to this address** and press **Save**.

The address must be `https` on the standard port, on the public internet, without a user name or a fragment. An address that points at a private network is refused. It is checked when you save and again before every delivery, and redirects are not followed. Once saved, the address is never shown again, only its host.

## When it is sent

A delivery is made when a lead's status changes here, whether a person changed it in the app or an event moved the lead.

It is not made when the new status just came from the same CRM. A status that arrives over the [inbound webhook](https://heymysocial.com/docs/webhooks/crm-inbound) is not sent back to where it came from, and a status HeyMySocial sent is recognized when the CRM echoes it.

One more case: when the CRM reports a status that is older than the one set here, the status here stands. It is sent so the CRM catches up, unless a delivery of that status was already made.

## The request

```text
POST <your address>
Content-Type: application/json
User-Agent: HeyMySocial-Webhook/1
X-HMS-Signature: t=1795597964,v1=d759547294f45f146d2d2c4d175bd96adf9efc660a0a6ea215c30136287befc8
X-HMS-Event: lead.status_changed
X-HMS-Delivery: 01m88r37j7htm1p0z2bdjtzhx0
```

```json
{
  "event": "lead.status_changed",
  "lead_id": "01m88r37e9pr4vxcetpf23vpvk",
  "external_id": "L-1042",
  "status": "won",
  "crm_status": "customer",
  "previous_status": "opportunity",
  "occurred_at": "2026-11-25T09:12:44+00:00",
  "delivery_id": "01m88r37j7htm1p0z2bdjtzhx0"
}
```

| Field | What it is |
|---|---|
| `event` | Always `lead.status_changed`. Also in the header `X-HMS-Event`. |
| `lead_id` | The HeyMySocial id of the lead. |
| `external_id` | Your CRM's id of the lead, when the lead is tied to a record of this connection. `null` for a lead the CRM has never sent. |
| `status` | The new status here: `new`, `contacted`, `qualified`, `disqualified`, `opportunity`, `won` or `lost`. |
| `crm_status` | The CRM's own name for that status, taken from the connection's status mapping, in lower case with underscores. `null` when the mapping names none. |
| `previous_status` | The status before the change, or `null`. |
| `occurred_at` | When the change was picked up for delivery, ISO 8601. |
| `delivery_id` | The id of this delivery. Also in the header `X-HMS-Delivery`. The same on every attempt. |

The body is sent as compact JSON. Do not rely on the order of the fields, and verify the signature over the bytes as they arrived.

To have `external_id` filled in for leads that began in HeyMySocial, let the CRM send the lead once over the inbound webhook with the HeyMySocial id in `data.lead_ref`. That ties the two records together.

## Verify it

The signature is the one all webhooks share: `X-HMS-Signature: t=<unix seconds>,v1=<hex>`, an HMAC-SHA256 of `<t>.<raw body>` with the signing secret of the CRM connection. It is the same secret your CRM signs its inbound requests with.

1. Take the raw body, before parsing it.
2. Check the header with the code under [Verify a signature](https://heymysocial.com/docs/webhooks#verify-a-signature). It refuses a wrong signature and a timestamp more than 5 minutes old.
3. Look up `delivery_id`. If you have handled it already, answer `200` and do nothing more.
4. Apply the status, remember the `delivery_id`, and answer.

## Answer it

Answer with any `2xx` status within 5 seconds. The connection is opened within 3 seconds or given up. Only the status code is read: nothing in your answer is stored or acted on. Do slow work after you have answered.

Anything else counts as a failed attempt: another status code, a redirect, a timeout, or a server that cannot be reached.

## Retries

A failed delivery is tried again, five attempts in all.

| After attempt | Earliest next attempt |
|---|---|
| 1 | 1 minute later |
| 2 | 5 minutes later |
| 3 | 30 minutes later |
| 4 | 2 hours later |
| 5 | None. The delivery is given up. |

The first attempt goes out right after the status change. Retries are sent by a job that runs every 30 minutes, so a retry leaves on the first run after its wait is over. Each attempt is signed again with the time of that attempt and carries the same `delivery_id`.

When a delivery is given up, the connection shows the error on its page. Every delivery is listed there under **Delivery log** with its outcome and number of attempts, and a failed or given-up delivery can be sent by hand with **Send again**.

A delivery whose address is refused, because it is no longer a public `https` address, is not retried. Correct the address under **Send status back**.

One status change is one delivery, however many times the same status is saved. Your endpoint can still receive a delivery twice, when your `2xx` did not reach us. That is what `delivery_id` is for.
