Webhooks
SDK methods for managing webhook endpoints, dispatching events to a recipient, and reading the delivery log.
client.webhooks manages the webhook endpoints of the calling service and, for v2 recipient endpoints, dispatches events to one recipient and reads their delivery log. See Webhooks overview for the v1 and v2 delivery engines.
import { PlatformXeClient } from '@caldera/platformxe-sdk';
const client = new PlatformXeClient({ apiKey: process.env.PLATFORMXE_API_KEY! });
List webhooks
// Untargeted endpoints only
const page = await client.webhooks.list({ limit: 50 });
// One recipient's v2 endpoints
const hostHooks = await client.webhooks.list({ recipientRef: 'host:1' });
for (const webhook of hostHooks.items) {
console.log(webhook.id, webhook.url, webhook.engineVersion, webhook.recipientRef);
}
list answers { items, total, page, limit }. Without recipientRef only the untargeted (v1) endpoints are listed. No list or get response carries a secret.
Create a webhook
// v1: an untargeted endpoint of the calling service
const v1 = await client.webhooks.create({
name: 'Order notifications',
url: 'https://your-app.example.com/webhooks/platformxe',
events: ['custom.order.created'],
});
// v2: a recipient endpoint
const v2 = await client.webhooks.create({
name: 'Host 1',
url: 'https://host-1.example.com/hooks',
events: ['booking.created'],
engineVersion: 2,
recipientRef: 'host:1',
});
// Store this now; it is never shown again
console.log(v2.secret); // "whsec_<one-time-secret>"
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | At least 3 characters |
url | string | Yes | HTTPS endpoint URL; a v2 URL may not carry credentials and must resolve to a public address |
events | string[] | Yes | Event types, non-empty. v2: *, prefix.* or event names (built-ins, custom.*, dotted names such as booking.created; webhook. is reserved; max 200 characters) |
engineVersion | 1 | 2 | No | 2 requires recipientRef; recipientRef with 1 is refused. With a recipientRef and no engineVersion the PLATFORMXE_WEBHOOK_ENGINE_DEFAULT environment variable decides (only the value 2 makes the endpoint v2; with anything else the create is refused), so pass engineVersion: 2 |
recipientRef | string | v2 | 1-200 characters, trimmed. Recipient endpoints are capped per recipient (default 5) and by a 50,000 per-service ceiling, not by the per-caller cap |
The result is { webhook, secret }. The secret is returned once (v1 and v2 alike).
Get, update, delete, test
const webhook = await client.webhooks.get('wh_1');
await client.webhooks.update('wh_1', { status: 'PAUSED' }); // name, url, events, status
await client.webhooks.delete('wh_1'); // { deleted: true }
const outcome = await client.webhooks.test('wh_1'); // { success, responseStatus?, responseTimeMs?, error? }
engineVersion and recipientRef can never change; delete and recreate the endpoint instead. An update that carries them unchanged (copy those two fields from a get result; recipientRef is null on an untargeted v1 endpoint) is accepted, but never send back a FAILING status (status accepts only ACTIVE or PAUSED); a changed value is VALIDATION_ERROR. get on another service's webhook, or another organisation's endpoint, is FORBIDDEN. An endpoint with no organisation (created before organisations were recorded) is not reached by a key with an organisation: it is not listed, and a get, update, delete, rotate or test is FORBIDDEN (since 2026-11-17; before, such a key could list and read it); see Manage webhooks.
status is ACTIVE, PAUSED or FAILING. A v2 endpoint becomes FAILING after 4 consecutive failed deliveries, keeps receiving new events, and returns to ACTIVE on its next successful delivery; a PAUSED endpoint receives nothing.
Rotate the secret
const { webhook, secret } = await client.webhooks.rotateSecret('wh_1');
The old secret stops verifying at once. The new secret is returned once.
Dispatch an event to one recipient
const result = await client.webhooks.dispatch(
{
recipientRef: 'host:1',
eventType: 'booking.created',
eventId: 'evt_2026_10_20_0001',
data: { bookingId: 'b_123' },
},
{ idempotencyKey: 'booking-b_123-created' },
);
console.log(result.targeted, result.created); // 1 1
Only the v2 endpoints of host:1 that subscribe to the event and are not PAUSED (ACTIVE or FAILING) receive it; targeted counts them. eventId is 1-200 visible ASCII characters (no spaces). Dispatch is idempotent per endpoint by eventId: a repeat creates no second delivery (created is 0). idempotencyKey is sent as x-idempotency-key and makes a repeat of the whole request answer the stored response.
The call returns once the delivery rows are recorded; the attempts run after the response and the retry sweep takes over, so the result does not mean the event was delivered.
Delivery log and redelivery
const log = await client.webhooks.deliveries('wh_1', { page: 1, limit: 20 });
for (const row of log.items) {
console.log(row.id, row.eventType, row.status, row.attemptCount, row.responseStatus);
}
const attempt = await client.webhooks.redeliver(log.items[0].id);
// { deliveryId, ok, status, responseTimeMs, reason }
Delivery rows never carry the payload or a secret; for a v2 endpoint responseSnippet is redacted and capped at 2 KB, for a v1 endpoint it is always null. redeliver re-sends a v2 delivery once with the same delivery id; a delivery that is being processed or is about to be retried is DELIVERY_IN_PROGRESS. A PAUSED endpoint can be redelivered to and stays PAUSED.
Verify a delivery
Verify with verifyWebhook from @caldera/keys-service; see Signature verification.
Errors
Failures throw PlatformXeError with a code from the closed set WEBHOOK_ERROR_CODES:
| Code | Status | Meaning |
|---|---|---|
BAD_REQUEST | 400 | Invalid JSON, or the request is not allowed (for example redelivering a v1 delivery) |
VALIDATION_ERROR | 400 | A field failed validation |
LIMIT_EXCEEDED | 400 | Per-caller (untargeted) or per-recipient (v2) endpoint cap, or the 50,000 recipient-endpoint ceiling, reached |
URL_REFUSED | 400 | Not HTTPS, credentials in the URL, a non-public host, or a DNS answer slower than 3 seconds |
UNAUTHORIZED | 401 | Missing or invalid API key |
FORBIDDEN | 403 | The key lacks the required scope, or the webhook belongs to another service or another organisation's endpoint, or a key with an organisation gets or changes (update, delete, rotate, test) an endpoint with no organisation |
NOT_FOUND | 404 | Unknown webhook or delivery, or a delivery of another service or another organisation's endpoint, or a key with an organisation reads the delivery log of, or redelivers a delivery of, an endpoint with no organisation |
DELIVERY_IN_PROGRESS | 409 | The delivery is being processed or is about to be retried; try again shortly |
INTERNAL_ERROR | 500 | Unexpected failure; nothing was changed |
The shared request wrappers can also answer RATE_LIMITED (429), and on dispatch CONFLICT (409, the same idempotency key in flight) and IDEMPOTENCY_UNAVAILABLE (503). They are outside WEBHOOK_ERROR_CODES and safe to retry.
Scopes required
| Method | Scope |
|---|---|
list, create, get, update, delete, test, rotateSecret | webhooks:manage |
deliveries, redeliver | webhooks:manage |
dispatch | webhooks:dispatch |