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

# Inbound webhooks

> Send a site's form, a Zapier zap or your backend's events into Sonar through a signed webhook URL.

A webhook makes anything that can POST a source for Sonar: a site's contact form, a Zapier zap, your backend. Each delivery becomes an event, which Sonar reads beside the webhook's name and description, so it can open a company, a contact and a deal from it like from any other message.

Webhooks are inbound only: Sonar receives deliveries, it does not send any.

## Create a webhook

In the [dashboard](https://dashboard.turtle.xyz), open your organization's Sonar, go to the **System** tab and connect a **Webhook**. You give it:

* a **name** and a **description** of what it receives, in your words. Sonar's agent reads both with every delivery;
* the **allowed sites** a browser may post from, such as `https://example.com`;
* optionally, a **thank-you page** for a plain HTML form, and a **record ID field**: the body field (dotted for nesting, such as `contact.id`) that names the record a delivery is about. A delivery that names a record an earlier one named is read as a new version of that record, the way a calendar edit is.

You get the webhook's URL and its **signing secret**. The secret is shown once, and again only when you rotate the webhook. Rotating gives it a new URL and a new secret, and the old URL stops answering at once.

## Send from a server

Sign the raw body with the signing secret, and send the signature in `X-Sonar-Signature`:

```http theme={null}
X-Sonar-Signature: sha256=<hex HMAC-SHA256 of the raw body, keyed with the signing secret>
```

A valid signature is the whole proof, wherever the request comes from. A signature that does not match answers `401`.

```bash curl theme={null}
BODY='{"company":"Pelagic Exchange","ask":"Integration"}'
SIG=$(printf '%s' "$BODY" \
  | openssl dgst -sha256 -hmac "$SIGNING_SECRET" \
  | awk '{print $NF}')

curl -X POST "$SONAR_WEBHOOK_URL" \
  -H "Content-Type: application/json" \
  -H "X-Sonar-Signature: sha256=$SIG" \
  -H "Idempotency-Key: form-2291" \
  -d "$BODY"
```

```typescript Node.js theme={null}
import { createHmac } from 'node:crypto';

const body = JSON.stringify({ company: 'Pelagic Exchange', ask: 'Integration' });
const signature = createHmac('sha256', process.env.SONAR_SIGNING_SECRET!)
  .update(body)
  .digest('hex');

await fetch(process.env.SONAR_WEBHOOK_URL!, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Sonar-Signature': `sha256=${signature}`,
    'Idempotency-Key': 'form-2291',
  },
  body, // sign and send the same bytes
});
```

## Send from a browser form

A browser cannot keep a secret, so an unsigned delivery is taken in only from one of the webhook's allowed sites: its `Origin`, or its `Referer`'s. Browser deliveries are also rate-limited per address.

A form can carry two reserved fields beside its own. Neither becomes part of the delivery.

| Field | What it does |
| - | - |
| `_redirect` | Where to send the person after the form posts. It must be on one of the allowed sites; otherwise they go to the webhook's thank-you page. |
| `_hp` | A honeypot. Add it as a hidden, empty field: a person never fills it in, so a delivery that does is answered like a success and dropped. |

```html theme={null}
<form action="https://YOUR_WEBHOOK_URL" method="post">
  <input name="name" required />
  <input name="email" type="email" required />
  <textarea name="message"></textarea>
  <input name="_hp" type="text" tabindex="-1" autocomplete="off" style="display:none" />
  <input name="_redirect" type="hidden" value="https://example.com/thanks" />
  <button type="submit">Send</button>
</form>
```

A plain form submission is answered with a `303` to the redirect, or with a short confirmation page when there is none. A script posting with `fetch` gets `{"ok": true}`.

## Bodies

* `application/json`: an object is read as sent, and anything else as `{"body": …}`.
* `application/x-www-form-urlencoded` and `multipart/form-data`: the form's fields. A field sent several times becomes a list, and files are left out.
* Any other content type: the body as text, under `body`.

## Deduplicate retries

Send an `Idempotency-Key` header of up to 200 characters. Deliveries with the same key are one event, so a retry never makes a second. Without a key, every delivery is its own event.

## Limits

* A body of at most 64 KB, and at most 200 form fields.
* 100 deliveries a day per webhook. Past that, deliveries are refused with `429` until the day's count drops.
* Browser deliveries are rate-limited per address.

## Responses

| Status | Meaning |
| - | - |
| `200` | Received: `{"ok": true}`, or a confirmation page for a plain form. |
| `303` | Received from a plain form, and the person is sent to the redirect or the thank-you page. |
| `400` | The body or the `Idempotency-Key` could not be read. |
| `401` | Invalid signature. |
| `403` | A browser delivery from a site the webhook does not allow. |
| `404` | No such webhook, or a URL that was rotated away. |
| `413` | The body is over 64 KB. |
| `429` | Rate limited, or the webhook has taken its deliveries for the day. |
| `500` | Something failed on our side. Retry with the same `Idempotency-Key`. |

A webhook you switched off answers like a success, and the delivery is dropped.

## Read what arrived

Read what your webhooks received with [List Webhook Deliveries](https://docs.turtle.xyz/sdk/sonar/reference/sonar/list-webhook-deliveries) (`GET /webhooks/deliveries`).


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