Overview
Webhooks allow you to receive real-time notifications when events occur in your CoverKit account. Instead of polling the API, webhooks push data to your server automatically.
Setting Up Webhooks
Register a webhook endpoint in your dashboard or via the API:
const webhook = await coverkit.webhooks.create({
url: 'https://your-server.com/webhooks/coverkit',
events: [
'quote.created',
'policy.created',
'policy.cancelled',
'claim.submitted',
'claim.approved',
'claim.paid',
],
});
// Save the webhook secret for signature verification
console.log('Webhook Secret:', webhook.secret);Event Types
Quote Events
quote.created - New quote generatedquote.expired - Quote expired without bindingPolicy Events
policy.created - Policy bound and activepolicy.renewed - Policy renewedpolicy.cancelled - Policy cancelledpolicy.expired - Policy term endedClaim Events
claim.submitted - New claim filedclaim.approved - Claim approvedclaim.denied - Claim deniedclaim.paid - Payout completedWebhook Payload
{
"id": "evt_abc123",
"type": "policy.created",
"createdAt": "2024-12-20T12:00:00Z",
"data": {
"id": "policy_xyz789",
"quoteId": "quote_abc123",
"status": "active",
"premium": 299,
"customer": {
"email": "customer@example.com"
}
}
}Signature Verification
Always verify webhook signatures to ensure requests come from CoverKit.
Verifying Signatures
// Node.js/Express example
app.post('/webhooks/coverkit', (req, res) => {
const signature = req.headers['coverkit-signature'];
const payload = req.body;
try {
const event = coverkit.webhooks.verify(
payload,
signature,
process.env.COVERKIT_WEBHOOK_SECRET
);
// Handle the event
switch (event.type) {
case 'policy.created':
handlePolicyCreated(event.data);
break;
case 'claim.approved':
handleClaimApproved(event.data);
break;
}
res.status(200).json({ received: true });
} catch (err) {
res.status(400).json({ error: 'Invalid signature' });
}
});Retry Policy
CoverKit retries failed webhook deliveries with exponential backoff:
- 1st retry: 1 minute
- 2nd retry: 5 minutes
- 3rd retry: 30 minutes
- 4th retry: 2 hours
- 5th retry: 24 hours
After 5 failed attempts, the webhook is marked as failed and no further retries are attempted.