Webhooks - cred.diy API documentation
Webhooks
Receive real-time notifications when events happen in your cred.diy project. Configure webhook endpoints from the Webhooks page in your dashboard.
Webhook Events
credits.issuedCredits were added to a user's accountcredits.deductedCredits were removed from a user's accountcredits.refundedA credit transaction was reversedbalance.lowUser's balance dropped below thresholdpurchase.completedA credit purchase was completedpurchase.failedA credit purchase payment failedswap.completedA credit swap was successfully executedreferral.completedA referral was successfully processedsubscription.createdA recurring checkout created a subscriptionsubscription.renewedA paid renewal added creditssubscription.cancel_scheduledA subscription will end after its paid periodsubscription.canceledA subscription endedsubscription.payment_failedA renewal payment failed and needs customer actionPayload Envelope
Every delivery includes a unique event id (sent as both id and event_id), the event name as event and type, and a created_at timestamp, alongside the event-specific fields. The same values are mirrored in the X-Cred-Event-Id and X-Cred-Timestamp headers. Use the event id to make your handler idempotent — transient failures (network errors, 5xx, 429) are retried up to three times.
Handling Webhooks
// Set up webhook listener (Express.js example)
const crypto = require('crypto');
app.post('/webhooks/cred', (req, res) => {
// Verify signature
const signature = req.headers['x-cred-signature'];
const expectedSig = crypto
.createHmac('sha256', 'your_webhook_secret')
.update(JSON.stringify(req.body))
.digest('hex');
if (signature !== expectedSig) {
return res.status(401).send('Invalid signature');
}
const event = req.body;
switch (req.headers['x-cred-event']) {
case 'credits.issued':
console.log('Credits issued:', event);
break;
case 'credits.deducted':
console.log('Credits deducted:', event);
break;
case 'purchase.completed':
console.log('Purchase completed:', event);
break;
}
res.status(200).send('OK');
});Testing Webhooks
Use the Test button next to each webhook endpoint in the dashboard to send a test.ping event. This verifies your endpoint is reachable and responding with a 200 status code before going live.
The test payload includes a X-Cred-Signature header so you can also verify your signature validation logic.
Webhook Security
- • Each endpoint has a unique secret generated at creation time
- • Verify the
X-Cred-Signatureheader using HMAC-SHA256 - • Failed deliveries are visible in the delivery log with full payload/response details
- • Always respond with
200 OKto acknowledge receipt
Your first credit is one request away.
Create a project, copy an API key, and issue a credit from your server.
