# Tracking webhook

The tracking webhook is for a form, a calculator or a backend you already have. Your server posts an event to the address of a tracking site and signs it; nothing on the page has to change. It takes the same events as the [events operation of the REST API](https://heymysocial.com/docs/api/operations/ingest-events), without an API key.

## Address and secret

Both belong to one tracking site. Open **Funnels**, choose the site, and look under **2. Or send leads from your own form or calculator**.

```text
POST https://heymysocial.com/hooks/{key}
```

- `{key}` is the public key of the site. It starts with `hms_pk_` and is not a secret. The screen shows the whole address under **Webhook address**.
- The **signing secret** starts with `hms_whsec_`. It is shown once, when the site is created, and again each time you press **Rotate signing secret**. Rotating makes the old secret stop at once.

A paused site answers `404`, like an address that does not exist.

## The request

Send `Content-Type: application/json` and the header `X-HMS-Signature: t=<unix seconds>,v1=<hex>`, where `v1` is the HMAC-SHA256 of `<t>.<raw body>` with the signing secret. [Webhooks overview](https://heymysocial.com/docs/webhooks#the-signature) explains the scheme. Send exactly one `v1`.

The body is one event, or a batch:

```json
{
  "events": [
    { "event_id": "form-7f3a9c2e", "type": "lead_created", "occurred_at": "2026-11-25T09:12:44+01:00", "external_id": "web-lead-2291", "consent_state": "not_applicable", "properties": { "contact": { "name": "Anders Holm", "email": "anders@example.com" } } },
    { "event_id": "crm-q-2291", "type": "lead_qualified", "occurred_at": "2026-11-25T15:40:00+01:00", "lead_external_id": "web-lead-2291", "consent_state": "not_applicable" }
  ]
}
```

- A batch holds 1 to 100 events. The body may be at most 256 KB (262,144 bytes).
- An event has the fields of the REST API: `event_id`, `type` and `occurred_at` are needed, and every event after `lead_created` names its lead with `lead_external_id` or `lead_id`. The [events operation](https://heymysocial.com/docs/api/operations/ingest-events) lists every field, and [event types](https://heymysocial.com/docs/reference/event-types) says what each type does.
- Leave `source` out. Events that arrive here get the source `webhook`, and any other value is refused.
- Add `"test": true` to try it out. A test event is shown on the site's screen under **3. Check that it works** and creates no lead.

## A signed request from the command line

Set `HMS_HOOK_URL` to the webhook address and `HMS_SIGNING_SECRET` to the secret, then:

```bash
BODY='{"event_id":"form-7f3a9c2e","type":"lead_created","occurred_at":"2026-11-25T09:12:44+01:00","external_id":"web-lead-2291","consent_state":"not_applicable","properties":{"contact":{"name":"Anders Holm","email":"anders@example.com"},"form":{"message":"Call me after four"}}}'
T=$(date +%s)
SIG=$(printf '%s.%s' "$T" "$BODY" | openssl dgst -sha256 -hmac "$HMS_SIGNING_SECRET" | sed 's/^.* //')

curl -X POST "$HMS_HOOK_URL" \
  -H "Content-Type: application/json" \
  -H "X-HMS-Signature: t=$T,v1=$SIG" \
  --data-binary "$BODY"
```

The answer:

```json
{
  "received": 1,
  "results": [
    { "status": "accepted", "event_id": "01m88r37e7vbkqty23npdydn7e", "lead_id": "01m88r37e9pr4vxcetpf23vpvk" }
  ]
}
```

`received` is the number of events in the request. `results` has one entry for each, in the order sent, with the same fields as in the REST API: `status` (`accepted`, `duplicate` or `rejected`), our `event_id`, `lead_id`, `sale_id`, a `warning`, and `errors` for a rejected event.

## Answers

The checks run in this order, and the first one that fails decides the answer.

| Status | Code | When |
|---|---|---|
| `429` | none | More than 600 requests in a minute for this site from one sender address. |
| `404` | `not_found` | No active tracking site has this key. |
| `413` | `validation_failed` | The body is larger than 256 KB. |
| `401` | `unauthenticated` | The signature header is missing, malformed or does not match. |
| `401` | `unauthenticated` | The signature matches, but the timestamp is more than 5 minutes from the server's clock. |
| `409` | `duplicate` | This exact request, with the same signature, was received before. |
| `422` | `validation_failed` | The body is not an event or a batch of 1 to 100 events. |
| `422` | none | Every event in the request was rejected. The body has `received` and `results`, and each result says why. |
| `200` | none | At least one event was accepted or was a duplicate. Read `results` for the rest. |

An error answer with a code has `code`, `message` and `retryable`. The id of the request is in the `X-Request-Id` header.

## Duplicates and retries

There are two layers, and they work together.

- **The request.** A request is remembered by its signature. Sending the very same bytes with the very same header again is answered `409` `duplicate` and nothing is processed.
- **The event.** An event is remembered by its `event_id`, and a lead, sale or refund also by its `external_id`. An event that was seen before is answered with the status `duplicate` and the result of the first time, and changes nothing.

So a retry is simple: sign the same body again with the current time and send it. The request is new, the events in it are recognized, and the answer is `200` with `duplicate` for each one that had already arrived. Nothing is counted twice.

## Receipts

A request with a valid signature is written down before it is processed. A request that is refused for its signature, its timestamp or as a replay is recorded too, without its body. The site's screen shows the latest under **Latest webhook deliveries**, as processed, duplicate, refused or not valid, with the reason for a refusal: the signature did not match, the timestamp was too old, or the same request was sent twice.

The body of an accepted request is kept with its receipt for 14 days, with contact details and form answers removed, and is then cleared. The receipt itself, which then holds no content, is removed after 90 days.
