# Webhooks

> Start a workflow from any system that can send an HTTP POST. Create the endpoints from the webhook trigger, choose test or prod mode, send JSON, wait for the result or run asynchronously and follow the progress over Server-Sent Events.

Source: https://docs.sommatic.ai/en/workflows/webhooks/ (updated 2026-11-26)

A webhook is the simplest way to put a workflow behind another system: the system sends a `POST`, Sommatic AI runs the
workflow with that request as input and answers with the result, or with a run id you can follow.

## Create the endpoints

1. Add [`webhook.trigger`](https://docs.sommatic.ai/en/nodes/webhook.trigger.md) (**Webhook Receiver**) as the first node of the workflow.
2. Open it and click **Create webhook endpoint** in the **Webhook URL** section.
3. Sommatic AI creates two **ingress bindings** for the workflow, one marked **TEST** and one marked **PROD**, and shows
   their URLs with a ready-to-copy `curl` command.

The last segment of the URL identifies the binding. It starts as an identifier generated for the workflow, and you can
change it to a readable slug from the same section.

## The URL

```text
POST https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/:mode/:bindingIdentifier
```

| Segment             | Values                                                                           |
| ------------------- | -------------------------------------------------------------------------------- |
| `mode`              | `test` runs the **draft**. `prod` runs the **default published version**.        |
| `bindingIdentifier` | The binding's id or its slug. Sommatic AI looks for the id first, then the slug. |

> **Warning: Test mode runs the draft**
>
> A `test` call runs whatever draft is saved at that moment. Give external systems the `prod` URL, and publish when the
> change is ready. A `prod` call to a workflow with no published version returns
> `No published version found for this workflow`.

## The request

Send any JSON body (up to 5 MB). The workflow receives the whole request as its input:

| Field     | Content                                    |
| --------- | ------------------------------------------ |
| `body`    | The JSON you sent.                         |
| `headers` | The request headers, with lowercase names. |
| `query`   | The query string parameters.               |
| `method`  | `POST`.                                    |

Downstream nodes read it with expressions:

```javascript
{{ $json.body.data.order_id }}                               // in the node right after the trigger
{{ $('Webhook Receiver').item.json.body.data.order_id }}     // from any later node
{{ $('Webhook Receiver').item.json.headers['x-request-id'] }}
```

## Call it

**curl**

```bash
curl -X POST "https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/prod/order-intake" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "order.received",
    "data": { "order_id": "ord_abc123", "total": 129.99, "currency": "USD" }
  }'
```

**JavaScript**

```javascript
const response = await fetch(
  'https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/prod/order-intake',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      event: 'order.received',
      data: { order_id: 'ord_abc123', total: 129.99, currency: 'USD' },
    }),
  },
);
const { success, result } = await response.json();
```

## Sync and async

By default the call is **synchronous**: it waits until the run ends and returns the instance, the steps and the
result.

```json
{
  "status": 200,
  "success": true,
  "message": "Operation completed successfully",
  "result": {
    "instance": { "id": "wf-flow-instance-…", "status": "completed" },
    "steps": [
      { "nodeId": "…", "operatorSlug": "webhook.trigger", "status": "success", "port": "out", "durationMs": 2 }
    ],
    "result": {
      "outcome_category": "success",
      "duration_ms": 1840,
      "final_output_envelope": { "node_id": "…", "port": "out", "payload": {} }
    }
  }
}
```

For long workflows, ask for **async** with `execution_mode=async`, in the query string or in the body. The call
returns at once with the run id:

```bash
curl -X POST "https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/prod/order-intake?execution_mode=async" \
  -H "Content-Type: application/json" \
  -d '{ "event": "report.generate", "data": { "period": "2026-04" } }'
```

```json
{
  "status": 200,
  "success": true,
  "message": "Operation completed successfully",
  "result": {
    "instance": { "id": "wf-flow-instance-…", "status": "running" },
    "execution_mode": "async"
  }
}
```

Then follow the run over SSE, or read it later from the
[Execution API](https://docs.sommatic.ai/en/api/reference/execution.md) (`flow-instance` and `flow-instance-result`).

## Follow progress over SSE

Open a Server-Sent Events stream for the workflow:

```bash
curl -N "https://api.sommatic.ai/workflow-orchestration/execution/stream?flow_definition_id=<flow-definition-id>&user_identity=<your-identity>"
```

Both parameters are required. Runs started by webhooks are broadcast to every stream open on that workflow. The
events are:

| Event                 | When                                                                                                     |
| --------------------- | -------------------------------------------------------------------------------------------------------- |
| `connected`           | The stream is open.                                                                                      |
| `webhook-received`    | A webhook call reached the workflow.                                                                     |
| `node-step-started`   | A node started.                                                                                          |
| `node-step-progress`  | A long-running node reported progress.                                                                   |
| `node-step-completed` | A node finished, with its port, duration and output (`status` is `failed` when it left through `error`). |
| `execution-completed` | The run finished; its `status` is `completed` or `failed`.                                               |
| `execution-failed`    | The run broke before the engine could finish it (for example, the orchestrator could not be reached).    |

## Paused workflows

You can pause a workflow per mode (see [Publishing](https://docs.sommatic.ai/en/workflows/publishing.md)). A `test` call to a paused workflow is
rejected with status `423` and creates no run. A `prod` call is accepted and creates a run with status `paused`, so the
call is kept on record.

## Errors

| Message                                        | Cause                                             |
| ---------------------------------------------- | ------------------------------------------------- |
| `Invalid webhook mode. Use "test" or "prod"`   | The `mode` segment is not `test` or `prod`.       |
| `Webhook binding not found`                    | No binding has that id or slug.                   |
| `No flow definition bound to this webhook`     | The binding does not point to a workflow.         |
| `No published version found for this workflow` | `prod` call and the workflow was never published. |

> **Note: Who may call your webhook**
>
> The webhook route does not take a Veripass token. If only one system should call it, check something it sends, such
> as a header, with a [`flow.if`](https://docs.sommatic.ai/en/nodes/flow.if.md) right after the trigger.

## Next steps

- [Triggers API](https://docs.sommatic.ai/en/api/reference/triggers.md): The webhook, chain and ingress binding endpoints.
- [Testing](https://docs.sommatic.ai/en/workflows/testing.md): Listen for a test call from the studio and watch the nodes run.
- [Expressions](https://docs.sommatic.ai/en/expressions.md): Read the request in any node.
