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

# Webhook trigger

> Start a flow when another system sends an HTTP request, signed with a secret only the two of you know.

A webhook trigger starts a flow when another system — a CRM, a shop, GitHub, your own backend — sends a `POST`
request to the trigger's URL. The flow runs without a contact, as an automation run, with the request available
under `flow.webhook`.

## Setting it up

1. Add a trigger to the flow and choose **Webhook**.
2. Pick a **verification preset** — *HMAC-SHA256*, *HMAC with timestamp*, *GitHub* or *Secret in a header* — and adjust the fields to
   what the sending system does (see [Verification](#verification)).
3. Click **Get URL**. The URL looks like `https://<your-workspace-host>/hooks/flow/<token>`; the token is random and
   is the only part that identifies the trigger. Copy it into the sending system.
4. Click **Generate secret** and copy the secret into the sending system. **It is shown once**: after you leave the
   panel only "Secret set" is shown. If the sending system issues its own signing secret, paste it under
   **Use a secret from the sender** instead.
5. [Publish](https://docs.fapost.in/using/publishing.md) the flow. Until the flow is published with the trigger active, the URL answers
   `404`, so you can set up the sender first.

Getting the URL needs the permission to edit the flow; generating or replacing the secret needs the permissions to
publish it and to **Manage automations**, because the secret is what lets an outside system start the flow. Replacing the secret is recorded in the
[activity log](https://docs.fapost.in/using/activity-log.md); the old secret stops working at once.

The secret never appears in the trigger's settings, the draft, a published version or a template: it is stored
encrypted, apart from the flow. Deleting the trigger (or changing its type) and publishing deletes its URL and secret.

## Verification

Every request is checked before anything else happens.

| Method | What the sender does |
| - | - |
| **HMAC-SHA256** | Signs the raw request body with the secret and sends the hex digest in the **signature header**, optionally after a **prefix** such as `sha256=`. |
| **Secret in a header** | Sends the secret itself in the **signature header** (for example `X-Webhook-Secret`). Simpler, but anyone who sees one request sees the secret: prefer HMAC when the sender supports it. |

**Against replays (HMAC only).** When the sender also sends the time it signed the request, set the **timestamp
header** and the **signed string** — what the sender actually signs, with `{raw}` for the body and the timestamp
header as a placeholder, for example `{header.X-Timestamp}.{raw}` or `v0:{header.X-Slack-Request-Timestamp}:{raw}`.
A request whose Unix time is further than the **tolerance** (300 seconds by default) from now is refused, and
because the timestamp is part of the signature, an old request cannot be resent with a fresh one. A timestamp
header without a signed string that contains it is refused at publish.

A secret in the query string is never accepted. The signature, timestamp, `Authorization` and `Cookie` headers, and
any header with `signature` in its name (such as GitHub's `X-Hub-Signature` next to `X-Hub-Signature-256`), are not
passed on to the flow.

## Delivery id: no request runs twice

Senders retry when they do not get an answer in time, so the same event can arrive more than once. Set **Delivery
id** to where the sender puts a unique id of each delivery, as one placeholder:

* `{header.X-GitHub-Delivery}` — a request header;
* `{body.id}` or `{body.event.id}` — a field of a JSON body;
* `{header.X-Delivery-Id|body.id}` — the first of several that is present.

The delivery id cannot be one of the headers the flow never sees — the signature or secret header, the timestamp,
`Authorization`, `Cookie`: the id is shown in the answer, the history and the run, and the secret would go with it.
Such a setting is refused at publish.

A request whose delivery id was already seen starts nothing and is answered `200` with `"status": "duplicate"`.
Repeats are recognised for a day by a quick check, and for as long as the earlier run is kept in the history.

Without a delivery id — the field is empty, or the request lacks it — every request gets a new id, so a resent
request starts the flow again. The builder warns about an empty field.

A run that failed can be started again by hand from its session page, with the same request — see
[Running a failed run again](https://docs.fapost.in/using/sessions.md#running-a-failed-run-again). That run answers nobody: the sender's request
was answered long ago.

## What the flow receives

| Variable | Value |
| - | - |
| `flow.webhook.body` | The JSON body, decoded; or the fields of a form post; or the body as text |
| `flow.webhook.query` | The query string parameters |
| `flow.webhook.headers` | The request headers, names in lower case, without the credentials and signature headers |
| `flow.webhook.method` | Always `POST` |
| `flow.webhook.delivery_id` | The delivery id (or the one generated for the request) |
| `flow.webhook.received_at` | When the request arrived, ISO 8601 |

The flow has no contact, so blocks that need one cannot be published in it; see
[Publishing](https://docs.fapost.in/using/publishing.md).

## Answers

| Code | Meaning |
| - | - |
| `202` | Accepted: the run is queued. The body is `{"status": "accepted", "delivery_id": "…"}` |
| `200` | A repeat of a delivery already accepted; nothing new runs. In *Wait for the flow's answer* mode, a repeat that arrives while the answer is kept (a minute) gets that answer instead |
| any | In *Wait for the flow's answer* mode: the status and body the flow answered (see below) |
| `401` | The signature, the secret or the timestamp did not check out, or no secret is set yet |
| `404` | No published, active webhook trigger behind this URL, or its flow is switched off in the flows list; a delivery answered `404` is not kept, so the sender's retry after the flow is turned on runs |
| `405` | A method other than `POST` |
| `413` | The body is larger than 256 KB |
| `415` | A `multipart/form-data` body: send JSON, a form (`application/x-www-form-urlencoded`) or text |
| `429` | Too many requests for this URL (see `flow.webhook.per_token_per_minute` in [Platform settings](https://docs.fapost.in/self-hosting/platform-settings.md)), or too many requests to unknown URLs from one address; wait for `Retry-After` |
| `503` | The workspace is stopped, or the trigger is paused for starting too many runs (see [Publishing](https://docs.fapost.in/using/publishing.md#when-a-trigger-starts-too-many-runs)); retry after `Retry-After` seconds |

## Response mode

**Response** in the trigger's settings chooses what the sender gets once the request is accepted:

* **Accept at once (202)** — the default. The sender gets `202` as soon as the run is queued; it does not wait
  for the flow.
* **Wait for the flow's answer** — the request is held open while the flow runs, for up to 30 seconds, and the
  sender gets what the flow answers:

  * the first **Respond to webhook** block the run reaches: its status (200–499) and its body, JSON or text, built
    from the run's variables — for example `{"order": "{{flow.webhook.body.id}}", "status": "received"}`. The
    block works inside a subflow too. The run goes on after it; a later block or the end of the
    run changes nothing;
  * otherwise, the end of the run: `200` with `{"status": "completed"}` (or `"cancelled"`, when an **End** block
    says so), or `500` with `{"status": "failed"}` when the run fails.

  If the flow does not answer in time, or more requests are already waiting than the platform allows, the sender
  gets the usual `202` and the run continues. Only the content type of an answer is set (`application/json` or
  `text/plain`); no other header comes from the flow.

Waiting holds a server worker for each request, so few may wait at once: by default 5 on the whole installation and
2 per workspace (`flow.webhook.sync_waiters_max`, `flow.webhook.sync_waiters_per_tenant`), for at most
`flow.webhook.sync_wait_seconds` seconds — see [Platform settings](https://docs.fapost.in/self-hosting/platform-settings.md). A burst of
deliveries, or runs of the same trigger queued behind each other, therefore gets `202` rather than the flow's
answer: a sender that needs the outcome of every delivery should not rely on it.

Outside this mode the **Respond to webhook** block does nothing; the builder warns when a flow has the block but no
trigger that waits for the answer.


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