Webhooks allow your application to receive real-time notifications when events occur in StateSet, eliminating the need for polling.
Overview
StateSet webhooks provide real-time event notifications delivered via HTTPS POST requests to your configured endpoints. Each webhook payload includes comprehensive event data and is secured with HMAC signatures.Key Features
- 🔄 Automatic retries with exponential backoff
- 🔐 Secure signatures using HMAC-SHA256
- 📊 Event versioning for backward compatibility
- 🎯 Granular event selection - subscribe only to events you need
- 📝 Detailed payloads with full resource data
- 🔍 Event replay for missed or failed deliveries
Setting Up Webhooks
1
Create Webhook Endpoint
Navigate to Dashboard → Settings → Webhooks and click Add Endpoint
2
Configure Endpoint
- Enter your HTTPS endpoint URL
- Select events to subscribe to
- Copy the signing secret for verification
3
Implement Handler
Create an endpoint that:
- Accepts POST requests
- Verifies signatures
- Processes events asynchronously
- Returns 2xx status quickly
4
Test Integration
Use the webhook simulator to send test events and verify your implementation
Webhook Security
Signature Verification
All webhooks include aStateset-Signature header for verification:
Security Best Practices
Webhook Payload Structure
All webhook events follow a consistent structure:Payload Fields
Event Types
Order Events
order.created
order.created
Triggered when: A new order is created
order.updated
order.updated
Triggered when: Order details are modified
order.cancelled
order.cancelled
Triggered when: Order is cancelled
order.fulfilled
order.fulfilled
Triggered when: Order fulfillment is complete
Return Events
return.created
return.created
Triggered when: Return is initiated
return.approved
return.approved
Triggered when: Return is approved
return.received
return.received
Triggered when: Returned items are received
Customer Events
customer.created
customer.created
Triggered when: New customer registers
customer.updated
customer.updated
Triggered when: Customer profile is updated
Inventory Events
inventory.low_stock
inventory.low_stock
Triggered when: Stock falls below threshold
inventory.out_of_stock
inventory.out_of_stock
Triggered when: Item goes out of stock
Handling Webhooks
Best Practices Implementation
Idempotency
Ensure your webhook handler is idempotent to safely handle duplicate deliveries:Retry Logic
StateSet automatically retries failed webhook deliveries with exponential backoff:Retry Schedule
After 8 failed attempts, the webhook is marked as failed and won’t be retried automatically.
Handling Failures
Your endpoint should:- Return
2xxstatus for successful processing - Return
4xxfor permanent failures (won’t retry) - Return
5xxfor temporary failures (will retry)
Testing Webhooks
Webhook Simulator
Test your webhook endpoint using our simulator:Local Development
Use ngrok or similar tools to test webhooks locally:Test Event Payloads
Webhook Management API
Webhook endpoints are managed from Dashboard → Settings → Webhooks: create endpoints, choose which events they receive, update or remove them, and view each endpoint’s signing secret. JS SDK support for webhook endpoint management has not shipped yet.Monitoring and Debugging
Webhook Logs
View webhook delivery attempts in the dashboard — each delivery log records the event id, delivery status, attempt count, last error, and next retry time, and failed deliveries can be retried manually from the same view. JS SDK support for webhook event logs has not shipped yet.Metrics and Alerts
Monitor webhook health:FAQ
How do I handle out-of-order events?
How do I handle out-of-order events?
Events may arrive out of order. Use the
created timestamp and resource state to handle this:What happens if my endpoint is down?
What happens if my endpoint is down?
StateSet will retry failed deliveries for up to 3 days with exponential backoff. You can also:
- Manually retry failed events from the dashboard
- Use the Event API to fetch missed events
- Implement webhook replay for recovery
Can I filter events by metadata?
Can I filter events by metadata?
Yes, you can configure webhook endpoints to filter events based on metadata:
How do I test webhook signature verification?
How do I test webhook signature verification?
Use our test signature generator:
Related Resources
- Webhook Events Reference - Complete list of events
- Security Best Practices - Security guidelines
- API Error Handling - Error codes and handling
- Event Replay API - Replay missed events
Need help? Contact api-support@stateset.com or visit our Discord community.