# Webhook Receiver

> Listens for external HTTP requests to trigger the workflow.

Source: https://docs.sommatic.ai/en/nodes/webhook.trigger/

- Slug: `webhook.trigger`
- Family: Triggers
- Version: 1.0.0
- Status: Available
- Execution: async

Listens for external HTTP requests to trigger the workflow.

This operator exposes a unique URL endpoint. When an external service (e.g., Stripe, Typeform, GitHub) sends a POST request to this URL, the workflow is instantiated with the request body as the payload.

**Features:**
- **Method Agnostic:** Can be configured to accept POST, GET, PUT.
- **Authentication:** Supports validating headers or signatures/secrets.
- **Response:** Can define what response to send back to the caller (Sync vs Async).

**Use Cases:**
- Integrating form submissions (Typeform).
- Reacting to payment events (Stripe Webhook).
- Building a custom API endpoint.

## Configuration

- `method` (string, optional): Default: `POST`. Allowed values: `POST`, `GET`, `PUT`, `PATCH`, `DELETE`.
- `path` (string, optional): Custom path segment (e.g. /my-hook).
- `response_mode` (string, optional): Immediate: Returns 200 OK instantly. Workflow End: Waits for workflow to finish and returns result. Default: `immediate`. Allowed values: `immediate`, `workflow_end`.

## Output ports

- `out` (default): Request received.
- `error`: Error

## Output contract

- `body` (object, optional)
- `headers` (object, optional)
- `query` (object, optional)

## In expressions

What a later node can read from this node's output with `$("Webhook Receiver").item.json.<path>` (write your node's label instead of `Webhook Receiver`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Webhook Receiver").item.json.body` (object) = `{…}`
- `$("Webhook Receiver").item.json.headers` (object) = `{…}`
- `$("Webhook Receiver").item.json.query` (object) = `{…}`
- `$("Webhook Receiver").item.json.headers.content-type` (string) = `"application/json"` (Not suggested by the editor)
- `$("Webhook Receiver").item.json.headers.user-agent` (string) = `"curl/8.7.1"` (Not suggested by the editor)
- `$("Webhook Receiver").item.json.body.event` (string) = `"order.received"` (Not suggested by the editor)
- `$("Webhook Receiver").item.json.body.data` (object) = `{…}` (Not suggested by the editor)
- `$("Webhook Receiver").item.json.method` (string) = `"POST"` (Not suggested by the editor)


## How it works

Entry node for workflows started by an HTTP call. It checks the request method and an optional shared secret, then outputs the request's `headers`, `body`, `query` and `method`.

1. What starts it: a `POST` to the backend at `/workflow-orchestration/trigger/webhooks/{mode}/{bindingIdentifier}`, where `bindingIdentifier` is an ingress binding id or slug that points to the workflow. The body limit is 5 MB. The call is synchronous by default; `execution_mode=async` (query string or body) returns at once with the instance id.
2. `mode` `test` runs the workflow draft; `prod` runs the default published version (or the latest one) and fails when none exists. The request becomes the run's input `{ body, headers, query, method }`.
3. The node resolves its config and compares the request method (upper-cased, default `GET`) with `method` (default `POST`) unless `method` is `ANY`.
4. Checks `auth_type`: `none` (default); `header` compares the header named `auth_config.header_name` with `auth_config.secret`; `basic` compares the whole `Authorization` header with `auth_config.secret`; any other value is rejected.
5. Outputs `{ headers, body, query, method }` on `out` with `meta.reply_mode`.

## In a workflow

### Node

```json
{
  "node_id": "node-webhook",
  "label": "Order webhook",
  "operator_slug": "webhook.trigger",
  "operator_version": "1.0.0",
  "config": {
    "method": "POST",
    "auth_type": "header",
    "auth_config": {
      "header_name": "x-webhook-token",
      "secret": "<shared-secret>"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "headers": {
      "content-type": "application/json",
      "x-webhook-token": "<shared-secret>"
    },
    "body": {
      "event": "order.received",
      "data": {
        "order_id": "ord_123",
        "total": 129.99
      }
    },
    "query": {},
    "method": "POST"
  },
  "port": "out",
  "meta": {
    "reply_mode": "sync"
  }
}
```

## Output ports (behaviour in the code)

### `out`

The method and authentication checks passed. Header names are lower-case.

```json
{
  "headers": {
    "content-type": "application/json",
    "user-agent": "curl/8.7.1"
  },
  "body": {
    "event": "order.received",
    "data": {
      "order_id": "ord_123",
      "total": 129.99
    }
  },
  "query": {},
  "method": "POST"
}
```

### `error`

The method or the authentication check failed. The output is the envelope `{ ok, errors, port, meta: { status_code } }`; `status_code` (405 or 401) is informational and does not change the HTTP response of the call.

```json
{
  "ok": false,
  "errors": [
    "Authentication Failed: Invalid header secret"
  ],
  "port": "error",
  "meta": {
    "status_code": 401
  }
}
```

## Behaviour in the code

- `auth_type`: Undeclared, like `auth_config` (`header_name`, `secret`) and `reply_mode` (default `sync`, only echoed in `meta`). Values are compared as plain strings; `basic` does not decode the header.
- `method`: The code also accepts `ANY`, which is not in the schema's enum. Since the backend route is `POST`-only, keep `POST` or `ANY`.
- `path`: Declared but not read: the URL is defined by the ingress binding. `response_mode` is not read either; use `execution_mode=async` on the call for an immediate response.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Method Not Allowed: Expected <method>, got <incoming>` | `error` | `method` is not `POST` or `ANY`. The ingress route only accepts `POST`, so any other value always fails. |
| `Authentication Failed: Invalid header secret` | `error` | `auth_type` is `header` and the header is missing or different. `Authentication Failed: Invalid basic auth` is the `basic` equivalent. |
| `Authentication Failed: Auth type <auth_type> not implemented` | `error` | `auth_type` is not `none`, `header` or `basic` (for example `jwt` or `hmac`). |
| `No published version found for this workflow` | `error` | Returned by the backend, before the node runs, for a `prod` call to a workflow that was never published. `Webhook binding not found` means the binding id or slug is wrong. |

## Notes and limits

- The ingress endpoint itself is unauthenticated; protection depends on `auth_type` in this node and on the binding. A failed check still creates a run, which ends on `error`.
- A paused workflow is not run: in `test` mode the call gets 423, in `prod` mode it gets 200 with a paused instance. In the editor with sample data the engine skips this node and passes the sample input on `out`.
- Downstream, read the payload at `{{ $json.body.<field> }}`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "webhook.trigger",
  "name": "Webhook Receiver",
  "category": "triggers",
  "version": "1.0.0",
  "description": "Listens for external HTTP requests to trigger the workflow.\n\n  This operator exposes a unique URL endpoint. When an external service (e.g., Stripe, Typeform, GitHub) sends a POST request to this URL, the workflow is instantiated with the request body as the payload.\n\n  **Features:**\n  - **Method Agnostic:** Can be configured to accept POST, GET, PUT.\n  - **Authentication:** Supports validating headers or signatures/secrets.\n  - **Response:** Can define what response to send back to the caller (Sync vs Async).\n\n  **Use Cases:**\n  - Integrating form submissions (Typeform).\n  - Reacting to payment events (Stripe Webhook).\n  - Building a custom API endpoint.",
  "capabilities": [
    "http",
    "webhook",
    "api",
    "ingress"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "method": {
        "type": "string",
        "enum": [
          "POST",
          "GET",
          "PUT",
          "PATCH",
          "DELETE"
        ],
        "default": "POST",
        "title": "HTTP Method"
      },
      "path": {
        "type": "string",
        "title": "Route Path",
        "description": "Custom path segment (e.g. /my-hook)."
      },
      "response_mode": {
        "type": "string",
        "enum": [
          "immediate",
          "workflow_end"
        ],
        "default": "immediate",
        "description": "Immediate: Returns 200 OK instantly. Workflow End: Waits for workflow to finish and returns result."
      }
    }
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "description": "The incoming HTTP request data.",
    "properties": {
      "body": {
        "type": "object"
      },
      "headers": {
        "type": "object"
      },
      "query": {
        "type": "object"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Received",
      "is_default": true,
      "description": "Request received."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "http",
    "api",
    "webhook",
    "trigger"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "method": {
      "type": "string",
      "enum": [
        "POST",
        "GET",
        "PUT",
        "PATCH",
        "DELETE"
      ],
      "default": "POST",
      "title": "HTTP Method"
    },
    "path": {
      "type": "string",
      "title": "Route Path",
      "description": "Custom path segment (e.g. /my-hook)."
    },
    "response_mode": {
      "type": "string",
      "enum": [
        "immediate",
        "workflow_end"
      ],
      "default": "immediate",
      "description": "Immediate: Returns 200 OK instantly. Workflow End: Waits for workflow to finish and returns result."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "The incoming HTTP request data.",
  "properties": {
    "body": {
      "type": "object"
    },
    "headers": {
      "type": "object"
    },
    "query": {
      "type": "object"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Received",
    "is_default": true,
    "description": "Request received."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
