New to webhooks? Start with our Webhook Quickstart for a
complete end-to-end tutorial.
Production Requirements
Your production webhook handler should:- ✅ Handle POST requests with JSON payloads
- ✅ Return 2xx status codes for successful processing
- ✅ Acknowledge promptly after verifying and durably accepting the event
- ✅ Handle retries gracefully (deduplicate repeated deliveries)
- ✅ Log events for debugging and monitoring
- ✅ Verify signatures for security
Retry Behavior
Automatic Retries: Network failures, timeouts, and non-2xx responses cause Magic Hour to schedule another delivery attempt:- Pattern: Scheduled delays of 1, 2, 4, 8, … minutes, capped at 60 minutes
- Expiry: Events more than 24 hours old are marked as failed and are no longer delivered
- Security headers: The timestamp and signature are regenerated for each delivery attempt
Production Handler Examples
Use the Python or Node.js signature verification examples to verify the timestamp and exact raw body. Then save the verified event before acknowledging it. This request handler outline uses an inbox table with a unique key. Use the same sequence with your database or durable queue.Best Practices
1. Deduplicate Webhook Deliveries
Magic Hour may deliver the same event more than once. Use its project ID and event type as a unique key. Let the database enforce uniqueness so simultaneous deliveries create one inbox record. Apply job-state changes transactionally and avoid replacing a terminal state with a delayedstarted event.
2. Quick Response Times
Keep the save step short. Run long processing, including media downloads and notifications, from the saved event in your worker.3. Comprehensive Logging
Record event types and job IDs for debugging. Keep raw webhook bodies, signature headers and signed media download links out of logs.4. Error Handling
Return the appropriate 4xx response for an invalid event or signature. If processing fails after you acknowledged delivery, retry it from the inbox.Local Testing
Start with Testing Your Secure Handler. Then verify these outcomes against your own storage.- Deliver the same signed event twice. Both requests should succeed and the inbox should contain one record.
- Make the inbox save fail. The handler should return 5xx.
- Restart the worker after a successful response. The saved event should still be available to process.
Deployment Considerations
Load Balancing
If using multiple servers, ensure webhooks can reach any instance:Health Checks
Add a health check endpoint:Monitoring
Track accepted events by type, inbox save failures, and how long the worker takes to process saved events. Use the project ID to match delivery logs with your worker logs.Next Steps
Secure Your Handler
Add signature verification for production security
Event Types Reference
Complete list of webhook events and payloads
Webhook API Reference
Detailed webhook API documentation
Quickstart Guide
New to webhooks? Start with our quickstart
Common Issues
Webhook timeouts?- Return 2xx promptly after signature verification and durable acceptance
- Process long-running work from a durable queue or saved event, not only in-process background tasks
- Check server resources and scaling
- Verify webhook is enabled in Developer Hub
- Check endpoint URL is correct and accessible
- Review server logs for errors
- Deduplicate deliveries using the project ID and event type
- Store processed deduplication keys
- Handle retries gracefully