Overview
Openfront’s webhook system automatically notifies your application when events occur, such as orders being created, products being updated, or payments being captured. This enables real-time integrations with external systems.How Webhooks Work
The webhook system (features/webhooks/webhook-plugin.ts) automatically captures events from all KeystoneJS models:
- Event Detection - Hooks capture create, update, and delete operations
- Payload Enrichment - Enrichers add related data to webhook payloads
- Event Batching - Events are batched every 100ms for performance
- Webhook Delivery - Events are sent to registered endpoints with signatures
- Retry Logic - Failed deliveries are retried with exponential backoff
Webhook Events
Events are automatically generated for all model operations:*.
Webhook Models
WebhookEndpoint
Webhook endpoints are configured in the admin panel:features/keystone/models/WebhookEndpoint.ts
WebhookEvent
Each webhook delivery is tracked:features/keystone/models/WebhookEvent.ts
Creating a Webhook Endpoint
Via Admin Panel
- Navigate to Webhooks > Webhook Endpoints
- Click Create Webhook Endpoint
- Enter your endpoint URL
- Select events to subscribe to
- Save - a secret key is automatically generated
Via GraphQL API
Webhook Payload Format
Webhooks are delivered as POST requests with this structure:Webhook Headers
Webhook requests include these headers:Verifying Webhook Signatures
Always verify webhook signatures to ensure authenticity:Payload Enrichment
Webhook payloads can be enriched with related data using enrichers.Order Enricher Example
The order enricher (features/webhooks/enrichers/order-enricher.ts) adds customer and line item data:
Creating Custom Enrichers
Create enrichers for any model:features/webhooks/enrichers/product-enricher.ts
Webhook Implementation Details
Automatic Hook Registration
The webhook system automatically wraps all KeystoneJS models:features/webhooks/webhook-plugin.ts
Batching and Performance
Webhooks are batched to improve performance:Retry Logic
Failed webhook deliveries are automatically retried:Testing Webhooks
Local Development
Use tools like ngrok to expose your local server:Webhook Testing Services
- webhook.site - Inspect webhook payloads
- RequestBin - Debug webhook requests
- Pipedream - Build webhook workflows
Manual Webhook Trigger
Trigger webhooks manually for testing:Best Practices
Security
Security
- Always verify webhook signatures
- Use HTTPS endpoints only
- Keep webhook secrets secure
- Implement IP allowlisting if possible
- Log all webhook attempts for auditing
Reliability
Reliability
- Return 200 OK quickly (within 5 seconds)
- Process webhooks asynchronously in background jobs
- Implement idempotency using delivery IDs
- Handle duplicate deliveries gracefully
- Monitor webhook delivery success rates
Error Handling
Error Handling
- Return appropriate HTTP status codes
- Log errors for debugging
- Implement dead letter queues for failed webhooks
- Alert on consistent failures
- Provide webhook retry mechanisms
Performance
Performance
- Subscribe only to needed events
- Batch process webhook data when possible
- Cache frequently accessed data
- Use webhook event IDs to prevent duplicate processing
- Monitor webhook processing times
Common Use Cases
Order Fulfillment Integration
Inventory Sync
Analytics Tracking
Related Resources
- Payment Providers - Payment webhook handling
- Shipping Providers - Shipping event tracking
- API Reference - Full API documentation