create_webhook
Register a webhook to receive real-time notifications when QR codes are scanned. Returns a one-time HMAC-SHA256 secret for secure verification of webhook signatures.
Instructions
Register a webhook endpoint to receive real-time notifications when QR codes are scanned. Returns an HMAC-SHA256 secret for verifying webhook signatures — store it securely, it is only shown once.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The endpoint URL that will receive POST requests with scan event data. | |
| events | No | Events to subscribe to. Currently supported: "qr.scanned". |
Implementation Reference
- Actual service-level implementation that creates a webhook - checks plan quota, generates a secret via nanoid, inserts into the database, and returns the created webhook.
export function createWebhook( url: string, events: string[], apiKeyId: number, plan: Plan = "free" ) { // Check plan quota const limits = PLAN_LIMITS[plan]; if (limits.maxWebhooks !== Infinity) { const [{ total }] = db .select({ total: count() }) .from(webhooks) .where(eq(webhooks.apiKeyId, apiKeyId)) .all(); if (total >= limits.maxWebhooks) { return { error: "WEBHOOK_LIMIT_REACHED" as const, limit: limits.maxWebhooks }; } } const secret = nanoid(32); const inserted = db .insert(webhooks) .values({ apiKeyId, url, secret, events: JSON.stringify(events), isActive: true, }) .returning() .get(); return { id: inserted.id, url: inserted.url, secret: inserted.secret, events: JSON.parse(inserted.events) as string[], is_active: inserted.isActive, created_at: inserted.createdAt, }; }