Webhooks Introduction
Webhooks enable your application to receive instant notifications about important events, making it easy to automate workflows and keep external systems in sync with Carbon’s API.What Are Webhooks?
Webhooks are HTTP callbacks triggered by specific events in your Carbon account. When an event occurs, Carbon sends a POST request to your configured webhook URL, allowing your server to process the event in real time.How Webhooks Work
Configure Your Webhook URL
Set your webhook endpoint using the API or dashboard. Make sure your server is ready to accept POST requests.
Event Triggered
When a relevant event occurs (e.g., a transaction is completed), Carbon automatically sends a POST request to your webhook URL with event details.
Key Features
Real-time Notifications
Real-time Notifications
Receive immediate updates for events such as transactions, account changes, and more.
Customizable
Customizable
Easily update your webhook URL or select which events you want to subscribe to.
Secure Delivery
Secure Delivery
Each webhook request includes a HMAC-SHA256 signature in the
X-Carbon-Baas-Signature header for verification. The signature is calculated by JSON-encoding the payload and hashing it with your secret key. Always validate the signature to ensure authenticity and prevent tampering.Example Webhook Events
Some common events you can subscribe to:account.incoming-transactionaccount.outgoing-transaction
Best Practices
Validate Webhook Signatures
Validate Webhook Signatures
Always verify the signature included in webhook requests to confirm they originate from Carbon.
How Signature Verification Works
Carbon signs each webhook with HMAC-SHA256 using your webhook secret and sends the signature in theX-Carbon-Baas-Signature header.Signature Generation:- JSON-encode the webhook payload
- Create HMAC-SHA256 hash using your secret key
- The result is sent in the
X-Carbon-Baas-Signatureheader
Finding Your Webhook Secret
Your webhook secret can be found in your Carbon dashboard on the Developer page.Implementation Examples
Security Best Practices
- Use constant-time comparison: Always use
hash_equals()(PHP),crypto.timingSafeEqual()(Node.js),hmac.compare_digest()(Python), or equivalent functions to prevent timing attacks - Validate before processing: Never process webhook data before verifying the signature
- Keep secrets secure: Store your webhook secret as an environment variable, never in your codebase
- Use HTTPS: Always use HTTPS endpoints to protect data in transit
Handle Retries Gracefully
Handle Retries Gracefully
If your server does not respond with a 2xx status code, Carbon will retry delivery up to 3 times. Ensure your endpoint can handle duplicate events safely.
Manual Resend Options
If automatic retries fail, you can manually resend webhook events:- Dashboard: Navigate to the Nexus menu in your Carbon dashboard to resend failed webhooks
- API: Use the Resend Webhook Event API endpoint for programmatic resending
Monitor and Log Events
Monitor and Log Events
Set up logging and monitoring for your webhook endpoint to track received events and troubleshoot issues quickly.