Appearance
Webhooks
Configure webhooks to receive real-time notifications about events in your Batch platform.
Overview
Webhooks allow your systems to react to events as they happen, enabling powerful integrations and automation.
What are Webhooks?
HTTP callbacks sent when events occur:
- Event happens (e.g., order created)
- Batch sends HTTP POST to your endpoint
- Your system receives event data
- Your system processes event
- Your system responds with 200 OK
Use Cases
Order Processing
- New order → Send to fulfillment system
- Order shipped → Update CRM
- Refund processed → Notify accounting
Loyalty Events
- Points earned → Send congratulations email
- Tier upgraded → Unlock special access
- Reward redeemed → Update inventory
Customer Updates
- New customer → Add to email list
- Customer updated → Sync to CRM
- Account verified → Enable features
Product Events
- Product scanned → Analytics tracking
- Inventory low → Reorder alert
- New product → Update external catalog
Analytics
- All events → Data warehouse
- Purchases → Attribution tracking
- Engagement → Behavioral analysis
Available Events
Orders
order.createdorder.updatedorder.paidorder.shippedorder.deliveredorder.cancelledorder.refunded
Customers
customer.createdcustomer.updatedcustomer.deletedcustomer.verified
Loyalty
loyalty.points_earnedloyalty.points_redeemedloyalty.tier_changedloyalty.reward_unlockedloyalty.campaign_completed
Products
product.createdproduct.updatedproduct.scannedproduct.verifiedinventory.updatedinventory.low_stock
Rewards
reward.createdreward.redeemedreward.expired
Setting Up Webhooks
Create Endpoint
- Navigate to Settings > Webhooks
- Click Add Endpoint
- Configure:
- URL: Your endpoint URL (HTTPS required)
- Description: What this webhook does
- Events: Select events to subscribe to
- Active: Enable/disable
Secure Your Endpoint
HTTPS Required:
- Must use HTTPS (not HTTP)
- Valid SSL certificate
- No self-signed certificates
IP Whitelisting:
- Whitelist Batch IPs (if your firewall requires)
Webhook Signatures:
- Verify request authenticity
- Prevent tampering
Webhook Payload
Request Format
Headers:
POST /your-endpoint HTTP/1.1
Host: yourserver.com
Content-Type: application/json
X-Batch-Signature: sha256=abc123...
X-Batch-Event: order.created
X-Batch-Delivery-ID: uuidBody:
json
{
"event": "order.created",
"timestamp": "2025-01-15T10:30:00Z",
"data": {
"id": "order-123",
"customer_id": "customer-456",
"total": 99.99,
"items": [...],
"status": "pending"
}
}Event-Specific Payloads
Order Created:
json
{
"event": "order.created",
"data": {
"id": "ord_abc123",
"number": "1001",
"customer": {
"id": "cus_xyz789",
"email": "customer@example.com",
"name": "John Doe"
},
"items": [
{
"product_id": "prod_123",
"quantity": 2,
"price": 25.00
}
],
"total": 50.00,
"status": "pending",
"created_at": "2025-01-15T10:30:00Z"
}
}Points Earned:
json
{
"event": "loyalty.points_earned",
"data": {
"customer_id": "cus_xyz789",
"points": 50,
"reason": "purchase",
"reference_id": "ord_abc123",
"balance": 550,
"earned_at": "2025-01-15T10:30:00Z"
}
}Verifying Webhooks
Signature Verification
Verify requests came from Batch:
javascript
const crypto = require('crypto');
function verifySignature(payload, signature, secret) {
const hmac = crypto.createHmac('sha256', secret);
const digest = 'sha256=' + hmac.update(payload).digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(digest)
);
}Process:
- Get signing secret from Batch dashboard
- Compute HMAC of raw request body
- Compare with
X-Batch-Signatureheader - Reject if mismatch
Handling Webhooks
Best Practices
Quick Response:
- Respond with 200 within 5 seconds
- Process asynchronously
- Queue for background processing
Idempotency:
- Use
X-Batch-Delivery-IDto detect duplicates - Store processed delivery IDs
- Skip duplicate events
Error Handling:
- Return 200 even if processing fails
- Log errors for investigation
- Retry failed processing separately
Example (Node.js):
javascript
app.post('/webhook', async (req, res) => {
// 1. Verify signature
if (!verifySignature(req.body, req.headers['x-batch-signature'], secret)) {
return res.status(401).send('Invalid signature');
}
// 2. Respond quickly
res.status(200).send('OK');
// 3. Process asynchronously
queue.add('process-webhook', {
event: req.body.event,
data: req.body.data,
deliveryId: req.headers['x-batch-delivery-id']
});
});Testing Webhooks
Test Events
Send test webhooks:
- Go to webhook settings
- Click Send Test Event
- Select event type
- View response
Local Testing
Test locally with tools:
ngrok:
bash
ngrok http 3000
# Use ngrok URL as webhook endpointwebhook.site:
- Temporary test endpoint
- View incoming requests
- Inspect payloads
Debugging
View webhook logs:
- Delivery attempts
- Response codes
- Response times
- Payload data
- Error messages
Retry Logic
Automatic Retries
If webhook fails:
- First retry: After 1 minute
- Second retry: After 5 minutes
- Third retry: After 30 minutes
- Fourth retry: After 2 hours
- Fifth retry: After 6 hours
Failure Conditions
Retried when:
- No response
- Timeout (> 10 seconds)
- HTTP 5xx errors
- Network errors
Not Retried
No retry for:
- HTTP 2xx (success)
- HTTP 4xx (client error)
- Invalid endpoint
Manual Retry
Manually retry failed deliveries:
- View webhook logs
- Find failed delivery
- Click Retry
Managing Webhooks
Edit Webhook
Modify existing webhook:
- Click webhook
- Update URL or events
- Save changes
Disable Webhook
Temporarily stop deliveries:
- Toggle Active switch to off
- No deliveries sent
- Can re-enable anytime
Delete Webhook
Permanently remove:
- Click Delete
- Confirm deletion
- Cannot be undone
Monitoring
Delivery Status
Track webhook health:
- Success rate
- Average response time
- Recent failures
- Total deliveries
Alerts
Get notified:
- Multiple failures
- Slow responses
- Endpoint unreachable
Logs
View delivery history:
- Timestamp
- Event type
- Response code
- Response time
- Payload
- Error message (if failed)
Security
Best Practices
Always:
- ✅ Use HTTPS
- ✅ Verify signatures
- ✅ Validate payload
- ✅ Check event types
- ✅ Rate limit processing
Never:
- ❌ Use HTTP
- ❌ Skip signature verification
- ❌ Trust payload blindly
- ❌ Expose webhook URL publicly
- ❌ Include secrets in URL parameters
IP Whitelisting
Restrict to Batch IPs:
52.12.34.56
52.12.34.57
52.12.34.58(Check dashboard for current IPs)
Advanced Use Cases
Event Streaming
Stream all events to data warehouse:
- BigQuery
- Snowflake
- Redshift
- S3 + Athena
Multi-System Sync
One webhook to multiple systems:
- Receive webhook
- Transform data
- Fan out to:
- CRM
- Analytics
- Email platform
- Inventory system
Custom Workflows
Build complex automations:
order.created
→ Check inventory
→ Reserve stock
→ Notify fulfillment
→ Send confirmation email
→ Track in analyticsTroubleshooting
Webhooks Not Received
Check:
- Webhook active?
- Correct URL?
- HTTPS working?
- Firewall blocking?
- Event subscribed?
Failed Deliveries
Common Issues:
- Endpoint timeout
- Server errors (5xx)
- Invalid SSL certificate
- Network issues
Solutions:
- Optimize response time
- Fix server errors
- Renew certificate
- Check network/firewall
Duplicate Events
Causes:
- Retries after timeout
- Your system didn't respond
Handle:
- Use delivery ID
- Implement idempotency
- Deduplicate in queue