Webhooks
Set up webhooks for real-time notifications
Webhooks allow you to receive real-time notifications when events occur in your application. Set up HTTP endpoints to automatically receive event data as it happens.
Overview
Real-time Notifications
Get instant updates when events occur in your system
Secure Delivery
Webhooks are signed with cryptographic signatures for verification
Reliable Delivery
Automatic retries ensure your webhooks are delivered
Easy Integration
Simple HTTP POST requests to your specified endpoints
Configuration
Setting Up Your Webhook
Configure Endpoint URL
Provide the HTTP endpoint where you want to receive webhook notifications.
Add Custom Headers
Configure any custom headers you need for authentication or routing.
Header | Value | Description |
---|---|---|
Authorization | Bearer token | Authentication token |
Content-Type | application/json | Always set to JSON |
X-Custom-Header | custom-value | Any custom headers you need |
Verify Webhook Signature
All webhooks include a cryptographic signature for security verification.
Webhook Payload
Every webhook request contains a standardized payload structure:
Payload Parameters
The type of event that triggered the webhook. Examples: user.created
, payment.completed
, order.updated
ISO 8601 timestamp when the event occurred
Example: 2024-01-15T10:30:00Z
The actual event data. Structure varies depending on the event type.
Security & Signature Verification
All webhooks are signed using SHA256 hashing with RSA-PKCS1v15 signing and Base64 encoding for maximum security.
Signature Header
The webhook signature is included in the X-Asteroid-Signature
header:
Always verify the webhook signature to ensure the request is authentic and hasn’t been tampered with.
Public Key for Verification
Use this Base64-encoded public key to verify webhook signatures:
JavaScript Implementation
Here’s a complete example of verifying webhook signatures in JavaScript:
Best Practices
Implement Proper Error Handling
Implement Proper Error Handling
Always return appropriate HTTP status codes:
200
- Successfully processed400
- Bad request/invalid payload401
- Unauthorized/invalid signature500
- Server error
Handle Duplicate Events
Handle Duplicate Events
Use the timestamp
and event data to detect and handle duplicate webhook deliveries.
Implement Timeout Protection
Implement Timeout Protection
Respond to webhooks within 30 seconds to avoid timeouts and retries.
Testing Your Webhooks
Use webhook.site to test your webhook integration during development. It provides a temporary URL that captures and displays all incoming webhook requests.
Test Payload Example
Troubleshooting
Webhook Not Receiving Events
Webhook Not Receiving Events
- Verify your endpoint URL is accessible from the internet
- Check that your server is running and responding to POST requests
- Ensure your firewall allows incoming connections
Signature Verification Failing
Signature Verification Failing
- Confirm you’re using the correct public key
- Verify you’re hashing the raw request body (not parsed JSON)
- Check that you’re using Base64 decoding for both the key and signature
Receiving Duplicate Events
Receiving Duplicate Events
- Implement idempotency using event timestamps and IDs
- Return 200 status code for successfully processed events
- Avoid returning error codes for already-processed events