Skip to Content

Manage endpoints

Register, update, pause, resume, rotate, and remove endpoints with the combined client or the standalone PostgreSQL provider.

An endpoint is a URL in one scope that subscribes to some of your event types. Endpoint management stores it with its status and encrypted signing secret. To let signed-in users manage their own endpoints, use the Better Auth plugin instead.

Register an endpoint

The webhooks client from installation has an endpoints API. The root client works in application scope; forScope() selects a named scope.

import { webhooks } from './webhooks.js'

const organization = webhooks.forScope({ type: 'organization', id: organizationId })

const { endpoint, secret } = await organization.endpoints.create({
  url: 'https://receiver.example/webhooks',
  description: 'Invoice notifications',
  eventTypes: ['invoice.paid'],
})

Both need the storage encryption key from installation, and every process that reads these endpoints needs the same key.

create() returns the plaintext signing secret once; no read returns it again. Show it to the endpoint owner once, or send it over a secure channel. Their receiver passes it to parseWebhook().

Change an endpoint

await organization.endpoints.update(id, { eventTypes: ['invoice.created', 'invoice.paid'] })
await organization.endpoints.pause(id)
await organization.endpoints.resume(id)
const { secret } = await organization.endpoints.rotateSecret(id, { graceMs: 3_600_000 })
await organization.endpoints.remove(id)
  • update: changes URL, description, subscriptions, or headers. A new URL is checked again.
  • pause: keeps subscriptions and queued deliveries.
    • The worker holds them until resume.
    • A delivery that a running worker found paused while it was due gets a full retry window after the resume, and any other keeps its old window, which can expire.
  • resume: checks the URL again, then queued deliveries send.
  • rotateSecret: returns a new signing secret. Both sign requests during the overlap (default and max 24 h).
  • remove: permanent. Clears stored secrets, cancels queued deliveries, and keeps a deleted record.

These calls return as soon as the record changes. A request already being sent can still arrive after a pause or remove. See endpoint changes while work is queued.

Send extra headers

Some receivers sit behind an API gateway that checks its own header, such as an API key, before the request reaches their code. Give the endpoint that header, and every request to it carries it:

const { endpoint } = await organization.endpoints.create({
  url: 'https://receiver.example/webhooks',
  eventTypes: ['invoice.paid'],
  headers: { 'x-api-key': apiKeyFromOwner },
})

// Replaces the whole set.
await organization.endpoints.update(endpoint.id, {
  headers: { authorization: `Bearer ${tokenFromOwner}` },
})

// Removes every header.
await organization.endpoints.update(endpoint.id, { headers: null })

The headers go out on every delivery attempt, every retry, and every test event. The signature headers are added after them. An update with headers replaces the whole set; null or {} removes them. Updates that leave out headers keep them.

Names starting with webhook- are reserved for the signature, and so are content-type, user-agent, and hop-by-hop names such as host or connection. These are rejected whatever their letter case, with INVALID_INPUT. An endpoint has at most 20 headers. Each name is an HTTP token of up to 100 characters, and each value is nonempty plain ASCII: visible characters, spaces, and tabs. All headers together hold at most 2 KiB in total as JSON, in UTF-8, so one long bearer token still fits. The management reference has the full rules.

Headers are stored encrypted with the same storage key as the signing secret, since they often hold credentials. Unlike the signing secret, reads return them: get, list, and every other result include headers, {} when there are none. The owner set them, so they may see them again. remove clears them with the secrets.

Send a test event

Let an owner check their receiver before real events arrive, or before resuming a paused endpoint:

const result = await organization.endpoints.sendTestEvent(id)
if (!result.ok) console.log(result.responseStatus, result.error, result.responseBody)

The call signs a good-webhooks.test event with the endpoint's signing secrets, sends it once, and returns what the receiver answered: ok, responseStatus, the first 4 KiB of responseBody, durationMs, and error. It waits at most 10 seconds. A test creates no delivery, is never retried, and doesn't count toward automatic pauses. Paused endpoints can be tested; deleted ones can't. The request leaves from the process that calls sendTestEvent, not from the worker.

Receivers built with parseWebhook() accept test events without listing them. See answer test events.

Automatic pauses

The worker pauses an endpoint when every attempt to it has failed for five days, or when it answers 410 Gone. Nothing is deleted. Subscriptions and queued deliveries stay, and resume works as usual once the receiver works again. Keep at least one worker running during a pause: the retry-window reset is recorded when a worker sees the paused endpoint. pauseReason tells the two kinds of pause apart:

pauseReasonMeaning
'owner'Paused with pause()
'failing'Every attempt failed for the whole period
'gone'The receiver answered 410 Gone
nullNot paused, or paused before schema version 5

To tell the owner when it happens, use the onEndpointPaused hook. Hooks are best-effort, so an endpoint list that shows pauseReason is the reliable record. Set endpointHealth: { pauseAfterMs } to change the period, or endpointHealth: false to turn automatic pauses off. The delivery reference has every option.

Limits

A scope holds at most 1,000 live endpoints, and each endpoint subscribes to 1 to 100 of your configured event names. To allow fewer, pass maxEndpoints to createWebhooks, createPostgresManagement, or the Better Auth plugin. It receives the scope (null for application scope) and returns a limit from 0 to 1,000:

maxEndpoints: (scope) => (scope === null ? 1000 : 3)

At the limit, create throws ENDPOINT_LIMIT (409 through Better Auth), so you can show your own message. Lowering a limit never removes endpoints; it only blocks new ones. URLs must use HTTPS, carry no credentials, and be at most 2,048 characters. The management reference lists every limit.

When a scope owner leaves

Standalone management doesn't know about your users. Call removeScope(scope) from your own deletion workflow to remove every endpoint in that scope:

import { createPostgresManagement } from 'good-webhooks/management/postgres'

const management = createPostgresManagement({ database: pool, eventTypes, encryptionKey })
await management.removeScope({ type: 'organization', id: organizationId })

The combined client doesn't expose removeScope. Build the provider with the same database, schema, and key as above, or create it first and pass it to createWebhooks({ management }).

On this page