Overview
The Merlin addon emits webhook events for every stage of the royalty data import lifecycle. By subscribing to these events, you can:
- Monitor import batch progress in real-time
- Trigger downstream processes when files are approved or completed
- Get notified of failures for immediate action
- Build custom integrations with external systems
- Maintain an audit trail of all import activities
All Merlin events are sent via HTTP POST to your configured webhook endpoint with standardized JSON payloads.
Quick Start
First, set up a webhook endpoint that accepts POST requests:
2. Subscribe to Merlin Events
Use the webhook configuration API to subscribe to Merlin events:
Users can subscribe to Merlin webhooks via the dashboard or programmatically using the webhook configuration endpoints. By default, Merlin events are not enabled - users must explicitly enable them.
Event Types
merlin.files.discovered
Emitted when the FTP scan discovers new royalty files from Merlin.
Importance: Medium
Automatic Retries: Yes (3 attempts)
Use Cases:
- Notify users that new files are available for review
- Trigger automated scanning of FTP for specific DSPs
- Log import batch initiation events
merlin.download.complete
Emitted when a file finishes downloading from FTP.
Importance: Low
Automatic Retries: Yes (3 attempts)
Use Cases:
- Track download progress for large batches
- Update UI with real-time file download status
- Monitor for slow or stalled downloads
merlin.import.approved
Emitted when a pending import is approved (manually or automatically).
Importance: Medium
Automatic Retries: Yes (3 attempts)
Use Cases:
- Notify managers of auto-approved imports
- Trigger downstream accounting processes
- Update external systems with approved metadata
merlin.import.completed
Emitted when an approved file finishes processing and is converted to royalty data.
Importance: High
Automatic Retries: Yes (3 attempts)
Use Cases:
- Trigger payment calculations
- Notify artists of new royalty data
- Generate reports or reconciliation
- Update data warehouse or BI systems
- Send notifications to team members
merlin.import.failed
Emitted when file processing fails due to errors.
Importance: Critical
Automatic Retries: Yes (3 attempts)
Use Cases:
- Alert operators of failed imports
- Create tickets for manual review
- Log errors for debugging
- Implement retry logic with user notification
- Track failure patterns for FTP issues
Webhook Payload Structure
All Merlin webhook events follow this standardized structure:
Security
Signature Validation
All Merlin webhook events can include HMAC-SHA256 signatures for verification. Enable this in your webhook configuration:
HTTPS Only
Always use HTTPS endpoints for production webhooks. HTTP endpoints are rejected.
Every webhook request includes these headers:
X-Royalti-Signature - HMAC-SHA256 signature (if enabled)
X-Royalti-Webhook-Id - Unique delivery ID
X-Royalti-Event-Type - Event type
X-Royalti-Tenant-Id - Your tenant ID
Content-Type: application/json
Best Practices
1. Return Quickly
Return a 2xx status code as soon as possible. Process events asynchronously:
2. Implement Idempotency
Webhooks may be delivered multiple times. Implement idempotent handlers:
3. Log All Events
Maintain an audit trail of all webhook deliveries:
4. Monitor Webhook Health
Track delivery success rates and error patterns:
Retry Logic
Failed webhook deliveries are automatically retried with exponential backoff:
- Attempt 1: Immediate
- Attempt 2: 1 second delay
- Attempt 3: 2 seconds delay
After 3 failed attempts, the event is logged but not retried. Check webhook health in your dashboard.
Status Code Guidelines:
2xx - Success (delivery accepted)
3xx - Temporary redirect (retried)
4xx - Client error (not retried)
5xx - Server error (retried)
Example: Complete Implementation
Troubleshooting
Events Not Being Received
-
Check webhook is enabled:
-
Verify event types are subscribed:
- Ensure
enabledEvents includes the Merlin events you want
- Default: all Merlin events are disabled
-
Check endpoint is publicly accessible:
- Merlin can only send webhooks to HTTPS endpoints
- Test with:
curl -X POST https://your-endpoint.com/webhooks/merlin
-
Review webhook delivery logs:
- Check dashboard for failed deliveries
- Look for error messages in
WebhookDeliveryLog
Signature Validation Failing
-
Verify secret token:
- Check stored secret in webhook config
- Ensure it matches what you’re using to verify
-
Check request body encoding:
- Use raw request body (not parsed JSON)
- Ensure consistent whitespace/formatting
-
Timing issues:
- Use constant-time comparison:
crypto.timingSafeEqual()
High Error Rates
-
Check endpoint availability:
- Ensure your server is running and accessible
- Check firewall/security group rules
-
Review response codes:
- Return 2xx for success
- Don’t timeout requests (timeout is 30 seconds)
-
Monitor webhook health:
- Use the metrics API to track success rates
- Set up alerts for high error rates
API Reference
See the Merlin Configuration and Merlin API documentation for complete details on webhook setup and usage.