Events
Receive real-time notifications for events in your Nexbic account. Webhooks enable your application to react to changes instantly.
Event Types
Every webhook event includes the event type, a unique ID, the relevant data, and an idempotency key.
Credits were added to a wallet
{ "wallet_id": "wlt_...", "amount": 1000, "balance": 5000 }Credits were deducted from a wallet
{ "wallet_id": "wlt_...", "amount": 250, "balance": 4750 }A transfer was initiated from a wallet
{ "from": "wlt_...", "to": "wlt_...", "amount": 500, "status": "completed" }A transfer was received in a wallet
{ "from": "wlt_...", "to": "wlt_...", "amount": 500, "status": "completed" }A new user account was created
{ "user_id": "usr_...", "email": "user@example.com" }A new session was created
{ "session_id": "nxb_ses_...", "user_id": "usr_..." }A session was revoked
{ "session_id": "nxb_ses_...", "reason": "logout" }Setup
Configure a webhook endpoint in your Nexbic dashboard to start receiving events.
// Create a webhook endpoint via the API
const webhook = await nexbic.webhooks.create({
url: "https://yourapp.com/api/webhooks/nexbic",
events: ["wallet.credit.added", "wallet.transfer.sent"],
description: "Production webhook"
});
console.log(webhook.secret); // "whsec_..." - save this for verificationcurl -X POST https://api.nexbic.dev/v1/webhooks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer nxb_sk_..." \
-d '{
"url": "https://yourapp.com/api/webhooks/nexbic",
"events": ["wallet.credit.added", "wallet.transfer.sent"]
}'Security
Every webhook request includes a signature header. Verify it to ensure the event came from Nexbic.
// Verify webhook signature in your endpoint
import { verifyWebhookSignature } from "@nexbic/sdk";
export async function POST(request) {
const payload = await request.text();
const signature = request.headers.get("x-nexbic-signature");
const secret = process.env.NEXBIC_WEBHOOK_SECRET;
const isValid = verifyWebhookSignature(payload, signature, secret);
if (!isValid) {
return new Response("Invalid signature", { status: 401 });
}
const event = JSON.parse(payload);
// Handle the event
return new Response("OK", { status: 200 });
}Reliability
If your endpoint does not respond with a 2xx status, Nexbic retries the delivery with exponential backoff.
Immediate delivery
0s delay
After 10 seconds
10s delay
After 60 seconds
60s delay
After 5 minutes
5m delay
After 30 minutes
30m delay
Event is discarded
After 5 failures
Example
A complete example of a webhook endpoint that handles wallet events.
// Full webhook handler example (Next.js App Router)
export async function POST(request: Request) {
const payload = await request.text();
const sig = request.headers.get("x-nexbic-signature")!;
if (!verifyWebhookSignature(payload, sig, process.env.WEBHOOK_SECRET!)) {
return new Response("Invalid signature", { status: 401 });
}
const event = JSON.parse(payload);
switch (event.type) {
case "wallet.credit.added":
await notifyUser(event.data.wallet_id, "Credits added!");
break;
case "wallet.transfer.sent":
await updateTransferStatus(event.data);
break;
default:
console.log("Unhandled event type:", event.type);
}
return new Response("OK", { status: 200 });
}Webhooks give you real-time visibility into every event happening in your Nexbic account.