Add a webhook
Two directions, two different mechanisms: inbound webhooks arrive at the integration-routes function and are normalized by a registry adapter into items records; outbound webhooks leave through integration-outbound (usually from a pipeline stage). See Integrations and webhooks.
Goal — inbound
Receive an external POST and turn it into a record.
Steps
- Create the integration (Add an integration) the webhook posts against. Set
config.event_pathif the event name lives inside the payload ("type"or"data.event"), andconfig.handler_nameto force an adapter — otherwise the adapter name falls back tointegration.provider, thengeneric-webhook(.framework/functions/integration-routes.ts). - Mint an API key for the sender.
integration-routesrequires a machine principal (x-api-key), and the key is authorized peraccount_id— optionally pinned tointegration_idandapp_id(.framework/functions/integration-routes.ts). See Auth and API keys. - Register or reuse an adapter.
webhook_handlersrows map a handler name →function_name; lookup prefers the app/account-scoped row and falls back to a global one, thenloadHandlerdynamically imports the module and takesadapt→handler→default(.framework/functions/_shared/webhook-registry.ts). Migration 004 seeds a globalgeneric-webhookhandler bound toadapters/generic-webhook-inbound, which stores the raw payload as awebhook_eventitem (.framework/migrations/004_core_rpc_and_broker.sql). - Adapter contract. The adapter receives
(payload, ctx)wherectxcarriesintegration,apiKey,accountId,appId,event,headers, and alogger; it returns{ type_slug, data, title?, status?, thread?, links?, external_id?, error?, retryable? }. A truthyerrormarks the deliveryfailed(orpendingwhenretryable); a result withtype_slugis created throughadmin-dataas anitemsrecord (.framework/functions/integration-routes.ts). - Post to it.
POST /api/integration-routes?slug=<integration-slug>withx-api-key: <key>and the payload body. The event name comes from thex-event-typeheader first, thenconfig.event_path(.framework/functions/integration-routes.ts).
Goal — outbound
Call an external URL from a pipeline.
Steps
- Add an
http_requeststage (arbitrary HTTP) or a webhook action whosehandler_module: 'webhook'routes toexecuteWebhookHandler— the webhook URL comes from the action's config (.framework/functions/_shared/pipeline-runner.ts). - For credentialed or retried sends, go through
integration-outboundinstead — see Add an integration. Deliveries are tracked inwebhook_deliverieswith exponential backoff.
Verify
- Inbound:
webhook_deliveriesshowsdirection: 'inbound'rows movingpending → delivered; the created item appears via/api/admin-data. - Outbound:
webhook_deliveriesshowsdirection: 'outbound'rows withresponse_status.
Common mistakes
- Human JWT instead of
x-api-key— the route requires a machine principal and returnsMachine principal required(401). - API key pinned to a different integration/app —
403 API key is not authorized. x-event-typevsevent_pathconfusion — the header wins; if the sender can't set headers, put the event inside the payload and setconfig.event_path.- Unregistered handler name —
config.handler_name(orprovider) that has nowebhook_handlersrow and no global fallback returnsHandler not found(404). - Registering handlers under the wrong scope — an app- or account-scoped
webhook_handlersrow shadows the global fallback for that scope only.