Overview
Webhooks allow you to receive real-time HTTP notifications when events happen in your LoyalPro account. Instead of polling our API, webhooks push data to your server as soon as events occur.
Real-time
Instant notifications when events occur
Reliable
Automatic retries with exponential backoff
Secure
Signed payloads for verification
Setting Up Webhooks
To receive webhook notifications, you need to configure an endpoint URL in your LoyalPro dashboard.
Go to your LoyalPro Dashboard → Developers → Webhooks
Click 'Add Endpoint' and enter your webhook URL
Select the events you want to receive
Copy your webhook signing secret for verification
// app/api/webhooks/loyalpro/route.ts
import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) {
const event = await request.json();
switch (event.type) {
case 'points.earned':
console.log('Points earned:', event.data);
// Handle points earned event
break;
case 'customer.created':
console.log('New customer:', event.data);
// Handle new customer event
break;
default:
console.log('Unhandled event type:', event.type);
}
return NextResponse.json({ received: true });
}Webhook Events
LoyalPro sends webhooks for various events. Here are all the available event types:
Customer Events
customer.createdTriggered when a new customer is enrolled
customer.updatedTriggered when customer details are modified
customer.deletedTriggered when a customer is removed
customer.tier_changedTriggered when a customer's tier changes
Points Events
points.earnedTriggered when points are awarded to a customer
points.redeemedTriggered when points are redeemed
points.expiredTriggered when points expire
points.adjustedTriggered when points are manually adjusted
Transaction Events
transaction.completedTriggered when a purchase is recorded
transaction.refundedTriggered when a transaction is refunded
Alert Events
fraud.detectedTriggered when suspicious activity is detected
churn.riskTriggered when a customer is flagged as at-risk
Security & Verification
LoyalPro signs all webhook payloads with a secret key. Always verify the signature to ensure the webhook came from LoyalPro.
Important Security Note
Never process webhooks without verifying the signature first. This protects you from malicious requests.
const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(JSON.stringify(payload))
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expectedSignature)
);
}
// In your webhook handler:
const signature = req.headers['x-loyalpro-signature'];
const isValid = verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET);
if (!isValid) {
return res.status(401).json({ error: 'Invalid signature' });
}Best Practices
Respond quickly
Return a 2xx response within 30 seconds. Process heavy tasks asynchronously using a job queue.
Handle duplicates
Use the event ID to detect and handle duplicate deliveries. Store processed event IDs.
Implement retries
LoyalPro will retry failed webhooks with exponential backoff for up to 72 hours.
Log everything
Keep detailed logs of received webhooks for debugging and auditing purposes.
Use HTTPS
Always use HTTPS endpoints in production. LoyalPro will not send webhooks to HTTP endpoints.
Next Steps
Was this page helpful?
Help us improve our documentation