# trigger.webhook

Runs the pipeline for every HTTP request on --route and --method

# trigger.webhook

```
trigger.webhook --route TEXT [--method GET|POST|PUT|PATCH|DELETE] [--auth none|jwt|hmac|api_key] [--credential TEXT] [--role TEXT…] [--auth-optional] [--errors show|hide] → webhook
```

Runs the pipeline for every HTTP request on `--route` and `--method`. Answers one key, `webhook`: `webhook: { body, query, params, headers, files, method, path, auth }`, and the same envelope is `$trigger` for the whole run. What the caller submitted is `webhook.body`: application/json → the parsed value; application/x-www-form-urlencoded → the form fields (percent-decoded); multipart/form-data → the text fields, with files under webhook.files.{field} as FileRef metadata; in both, a repeated field (a checkbox group sharing one name), field[] and field[0] become arrays. GET requests → webhook.body is null. Request context: webhook.query (URL query params), webhook.params (path params), webhook.headers (a safe subset), webhook.path (request path), webhook.method (HTTP method). Use --auth jwt|hmac|api_key and --credential <id> to protect the route, --role to require a role. hmac checks a vendor's signature exactly as its credential describes (what is signed, which header, a timestamp window): help("pipeline/examples/webhook-signatures"). jwt auth checks Authorization: Bearer header first, then the cookie the credential names (`cookie_name`, default zebflow_session) — verified claims are webhook.auth. Add --auth-optional for a public page that only wants to know who is signed in: a valid token fills webhook.auth, anything else leaves it null and the page renders for the guest. Streaming: clients that send Accept: text/event-stream receive an SSE stream instead of a single response. Nodes that emit signals via the ExecutionBus (or return __signal in their output) are forwarded as event: signal messages. The final pipeline result is sent as event: done (or event: error) and the stream closes. The pipeline definition is identical for both modes — the Accept header is the only switch.

## Flags

- `--route` (required): The path this project serves, under /wh/{owner}/{project}. Starts with /; `:name` is a path param. Examples: /blog, /api/users/:id.
- `--method`: HTTP method: GET (default when omitted, at save and at run alike), POST, PUT, PATCH, DELETE. A GET route also answers HEAD: the same run and headers, no body.
- `--auth`: How the route is guarded: none (default), jwt, hmac, api_key. Anything but none needs --credential.
- `--credential`: The credential (its id) that verifies --auth: a JWT signing key, an hmac signature check (help pipeline/examples/webhook-signatures) or an API key.
- `--role`: A role allowed in, repeated (`--role editor --role admin`): one entry of the JWT `roles` claim must match. None: any authenticated caller.
- `--auth-optional`: With --auth jwt: the route stays public; a valid token fills webhook.auth, no token or a bad one leaves it null instead of answering 401. For a public page that greets a signed-in user.
- `--errors`: show or hide: what a failure on this route reveals to the caller, overriding the project's errors switch (Settings → Addressing). Absent: the project decides. The status code is the same either way.

## Examples

### A public page

```
| trigger.webhook --route /blog --method GET
```

Served at `/wh/{owner}/{project}/blog`. Then a query, then `web.response.send --template pages/blog.tsx`.

It answers:

```json
{
  "webhook": {
    "body": null,
    "params": {},
    "query": {
      "page": "2"
    },
    "headers": {},
    "path": "/blog",
    "method": "GET"
  }
}
```

### A form POST

```
| trigger.webhook --route /contact --method POST
```

`<input name="email">` arrives as `input.webhook.body.email` (`$trigger.body.email` anywhere later); a file field is `input.webhook.files.<name>`.

It answers:

```json
{
  "webhook": {
    "body": {
      "email": "a@example.com",
      "message": "Hi"
    },
    "params": {},
    "query": {},
    "headers": {},
    "path": "/contact",
    "method": "POST"
  }
}
```

### A protected admin route

```
| trigger.webhook --route /admin/posts/:id --method GET --auth jwt --credential jwt_main --role editor
```

Without a valid token the request is refused before any node runs, and the credential's `auth_redirect` decides where a browser goes.

It answers:

```json
{
  "webhook": {
    "body": null,
    "params": {
      "id": "42"
    },
    "query": {},
    "headers": {},
    "path": "/admin/posts/42",
    "method": "GET",
    "auth": {
      "sub": "u_1",
      "roles": [
        "editor"
      ]
    }
  }
}
```

## Used in

- [Agentic Scheduling (AI + Cron)](/examples/agentic-scheduling.md)
- [Let an app build inside its own project (control door)](/examples/app-control-door.md)
- [Auth and Authorization](/examples/auth-and-authorization.md)
- [Blog with Admin](/examples/blog-with-admin.md)
- [Cookie + JWT Authentication](/examples/cookie-jwt-auth.md)
- [Forum with Real-Time Chat](/examples/forum-with-chat.md)
- [Sign in to a published MCP server (OAuth)](/examples/mcp-oauth-login.md)
- [Sign in with Google (OAuth login)](/examples/oauth-login-google.md)
- [Real-Time Game (WebSocket State Sync)](/examples/realtime-game.md)
- [Web Scraping + Data Pipeline](/examples/scraping.md)
- [TTS API + Frontend Page](/examples/tts-with-page.md)
- [Webhook → TSX Page](/examples/webhook-page-tsx.md)
- [REST API + PostgreSQL](/examples/webhook-restapi-postgres.md)
- [Webhook signatures from any vendor](/examples/webhook-signatures.md)
