Overview
Webhooks allow your Spree store to send real-time HTTP POST notifications to external services when events occur. When an order is completed, a product is updated, or inventory changes, Spree can automatically notify your CRM, fulfillment service, analytics platform, or any other system. Webhooks are built on top of Spree’s event system, providing:- Multi-store support - Each store has its own webhook endpoints
- Event filtering - Subscribe to specific events or patterns with wildcards
- Secure delivery - HMAC-SHA256 signatures for payload verification
- Automatic retries - Failed deliveries retry with exponential backoff
- Full audit trail - Track every delivery attempt with response codes and timing
How Webhooks Work
- An event is published (e.g.,
order.completed) - The
WebhookEventSubscriberreceives all events - It finds active webhook endpoints subscribed to that event
- For each endpoint, it creates a
WebhookDeliveryrecord and queues a job - The job sends an HTTP POST request with the event payload and HMAC signature
Creating Webhook Endpoints
Via Admin Panel
Navigate to Settings → Developers → Webhooks in the admin panel to create and manage webhook endpoints.Via Code
Endpoint Attributes
| Attribute | Type | Description |
|---|---|---|
url | String | The HTTPS endpoint URL to receive webhooks |
active | Boolean | Enable/disable delivery to this endpoint |
subscriptions | Array | Event patterns to subscribe to |
secret_key | String | Auto-generated key for HMAC signature verification |
store_id | Integer | The store this endpoint belongs to |
Event Subscriptions
Thesubscriptions attribute controls which events trigger webhooks to this endpoint.
Subscribe to Specific Events
Subscribe to Event Patterns
Use wildcards to subscribe to multiple related events:Subscribe to All Events
Leave subscriptions empty or use* to receive all events:
Webhook Payload
Each webhook delivery sends a JSON payload with the following structure:| Field | Description |
|---|---|
id | Unique UUID for this event |
name | Event name (e.g., order.completed) |
created_at | ISO8601 timestamp when event occurred |
data | Serialized resource data |
metadata | Additional context including Spree version |
HTTP Request Details
Headers
Each webhook request includes these headers:| Header | Description |
|---|---|
Content-Type | application/json |
User-Agent | Spree-Webhooks/1.0 |
X-Spree-Webhook-Event | Event name (e.g., order.completed) |
X-Spree-Webhook-Signature | HMAC-SHA256 signature for verification |
Verifying Webhook Signatures
To ensure webhooks are genuinely from your Spree store, verify the signature:Delivery Status & Retries
Automatic Retries
Failed webhook deliveries automatically retry up to 5 times with exponential backoff. This handles temporary network issues and endpoint downtime.Checking Delivery Status
Delivery Attributes
| Attribute | Description |
|---|---|
event_name | Name of the event delivered |
payload | Complete webhook payload sent |
response_code | HTTP status code (nil if pending) |
success | Boolean indicating 2xx response |
execution_time | Delivery time in milliseconds |
error_type | 'timeout', 'connection_error', or nil |
request_errors | Error message details |
response_body | Response from endpoint (truncated) |
delivered_at | Timestamp of delivery attempt |
Configuration
Enabling/Disabling Webhooks
Webhooks are enabled by default. To disable globally:SSL Verification
SSL verification is enabled by default in production. In development, it’s disabled to allow testing with self-signed certificates:Available Events
Webhooks can subscribe to any event in Spree’s event system. See Events for a complete list. Common webhook events include:| Event | Description |
|---|---|
order.completed | Order checkout finished |
order.canceled | Order was canceled |
order.paid | Order is fully paid |
shipment.shipped | Shipment was shipped |
payment.paid | Payment was completed |
product.created | New product created |
product.updated | Product was modified |
customer.created | New customer registered |
Testing Webhooks
In Development
Use tools like ngrok or webhook.site to test webhooks locally:In Tests
Best Practices
Respond quickly
Return a 2xx response as fast as possible. Process webhook data asynchronously in a background job.
Verify signatures
Always verify the
X-Spree-Webhook-Signature header to ensure the webhook is authentic.Handle duplicates
Use the event
id to detect and handle duplicate deliveries. Webhooks may be retried.Subscribe selectively
Only subscribe to events you need. Use specific patterns rather than
* when possible.Troubleshooting
Webhooks Not Delivering
- Check that webhooks are enabled:
Spree::Api::Config.webhooks_enabled - Verify the endpoint is active:
endpoint.active? - Confirm the endpoint subscribes to the event:
endpoint.subscribed_to?('order.completed') - Check the event has a
store_idmatching the endpoint’s store
Signature Verification Failing
- Ensure you’re using the raw request body (not parsed JSON)
- Verify you’re using the correct
secret_keyfor this endpoint - Check that no middleware is modifying the request body
Deliveries Failing
Check the delivery record for details:Related Documentation
- Events - Understanding Spree’s event system
- Customization Quickstart - Overview of all customization options
- Dependencies - Customizing Spree services

