Prompt
How do I add webhooks to an API product?
Latest observation
Nov 15, 2026
OpenAI APIWeb search: off
Adding webhooks to an API product usually means exposing event notifications so your users’ systems can receive updates when something happens in your API.
Basic approach
1. Decide what events you’ll support
Pick the actions that should trigger notifications, for example:
order.createdpayment.faileduser.updatedinvoice.paid
Keep the event list small and clear at first.
2. Define the webhook format
Standardize the payload and headers. Common fields:
event_typeevent_idcreated_atdata(the resource details)
Example payload:
{
"event_type": "order.created",
"event_id": "evt_123",
"created_at": "2026-11-15T12:00:00Z",
"data": {
"order_id": "ord_456",
"amount": 4999,
"currency": "USD"
}
}
3. Let customers register webhook endpoints
Provide API or dashboard support for:
- webhook URL
- subscribed event types
- secret/signing key
- optional active/inactive status
Example endpoint:
POST /webhooks
4. Secure the delivery
Use:
- HTTPS only
- signature verification for authenticity
- replay protection using timestamps or nonces
- optional IP allowlisting if appropriate
A common pattern is an HMAC-SHA256 signature header:
X-Signature: sha256=...
X-Event-Id: evt_123
X-Timestamp: 1731672000
5. Deliver asynchronously and reliably
Webhook delivery should be off the main API request path. Use a background worker or queue.
Best practices:
- retry failed deliveries with exponential backoff
- time out quickly
- treat any non-2xx response as failure
- store delivery attempts
- deduplicate by
event_id
6. Support retries and idempotency
Customers may receive the same event more than once, so tell them to dedupe using event_id.
Your system should:
- retry transient failures
- not create duplicate events unnecessarily
- make deliveries idempotent on your side if possible
7. Build webhook management endpoints
Useful endpoints:
POST /webhooks— create subscriptionGET /webhooks— list subscriptionsGET /webhooks/{id}— inspect a subscriptionDELETE /webhooks/{id}— remove a subscriptionPOST /webhooks/{id}/test— send a test eventGET /webhook-deliveries— view delivery logs
8. Document it well
Your docs should include:
- available event types
- sample payloads
- signature verification steps
- retry behavior
- response expectations
- test event instructions
A simple architecture
- Something happens in your app
- You create an event record
- A worker picks up the event
- Worker finds matching webhook subscriptions
- Worker sends POST requests to customer URLs
- You log success/failure and retry if needed
Example delivery request
POST /customer/webhook HTTP/1.1
Content-Type: application/json
X-Event-Id: evt_123
X-Event-Type: order.created
X-Signature: sha256=abcd1234
{
"event_type": "order.created",
"event_id": "evt_123",
"data": {
"order_id": "ord_456"
}
}
Important pitfalls to avoid
- Don’t send webhooks synchronously during user-facing requests
- Don’t omit signatures
- Don’t rely on one delivery attempt
- Don’t make payloads inconsistent across event types
- Don’t include sensitive data unless necessary
If you want, I can also give you:
- a database schema for webhook subscriptions and deliveries,
- a Node/Python implementation, or
- a full webhook design spec for your API product.