Skip to main content
Webhooks expose an HTTP endpoint that external services can call. Use them to push events from external systems into Notion, such as a GitHub push, Stripe event, Zendesk ticket update, or any service that can send an HTTP webhook.

Basic webhook

Define a webhook capability on your worker like this:
After you deploy, Notion creates a URL for each webhook capability. Give that URL to the external service as its webhook destination:

The event object

The execute function receives an array of WebhookEvent objects. The array currently contains one event, but may contain multiple events in the future.
Use the external provider’s own event ID for idempotency when the payload includes one. deliveryId is useful when Notion retries running your worker, but a provider may redeliver the same event as a new HTTP request.

Webhook URLs

Webhook URLs include a unique ID that acts as a shared secret:
Use the CLI to print the URLs for a deployed worker:
For scripts, use JSON or tab-separated output:
Treat webhook URLs as secrets. Anyone with the full URL can send events to the webhook endpoint unless you add provider-specific signature verification inside your worker.

Verify requests

Most webhook providers can sign requests with a shared secret. Store the signing secret as a worker secret, verify each request using event.rawBody and event.headers, and throw WebhookVerificationError when verification fails:
Set the secret before deploying or push it from your local .env file:
See Secrets for more ways to manage worker environment variables.
After 5 consecutive WebhookVerificationError failures, Notion blocks that webhook before running your handler. Redeploy the worker to reset the failure counter.

Execution and retries

When a webhook request reaches Notion, Notion validates the URL, enqueues the event, and responds with 202 Accepted. Your worker runs asynchronously after the HTTP response is sent. If your handler throws WebhookVerificationError, Notion records a verification failure and does not retry that event. If your handler throws another error, Notion retries the worker run up to 3 times. Successful runs reset the consecutive verification failure counter.

Use Notion from a webhook

Webhook handlers receive the same context object as other capabilities, including context.notion, the Notion API SDK client:
For webhooks, context.notion is not automatically authenticated. To call the Notion API, create an internal integration, give it access to the relevant pages or databases, and store the integration token in NOTION_API_TOKEN:
At runtime, context.notion reads process.env.NOTION_API_TOKEN and uses it as the Notion API client token. For more information about creating an integration token for a worker, see Using Notion API from a worker.

Inspect runs

Use worker run logs to debug webhook executions:
To find recent webhook runs quickly:
See the CLI command reference for all ntn workers flags and options.

Next steps

Secrets

Store webhook signing secrets and API keys.

Notion API

Read and write Notion data from a webhook handler.

OAuth

Authenticate with third-party APIs from your webhook.

SDK reference

Detailed API docs for worker.webhook() and WebhookVerificationError.