Events and webhooks
Use events.read and the read permission for the resource. Process data in order, record event_id and save next_cursor after successfully processing each batch. Keep the cursor even on empty pages. On 410, reread authorized resources and restart polling.
Select events and register a public HTTPS endpoint in the ERP. During verification, return JSON containing the same challenge. Keep the raw request body to verify the signature before processing the JSON.
Validate Kaserk-Timestamp (Unix seconds), Kaserk-Event-Id and Kaserk-Signature. Use constant-time comparison for the hex HMAC SHA-256 of timestamp + dot + ID + dot + raw body, using the endpoint’s secret. Reject timestamps outside your tolerance and already processed IDs. Store the signing secret separately from the API key.
Deliveries can repeat or arrive out of order. Persist the event before acknowledging it. Failed deliveries are retried for up to 24 hours. An admin can review failures and replay deliveries. Polling retains metadata for 30 days.
curl --fail-with-body \
-H "Authorization: Bearer ${KASERK_API_KEY}" \
"https://api.kaserk.com/v1/events?limit=50"JavaScript example
import { createHmac, timingSafeEqual } from 'node:crypto';
// rawBody is a Buffer captured before JSON parsing. Supply the destination's
// signing secret from your server's secret manager and persist events separately.
export function verifyWebhook(rawBody, headers, secret, now = Date.now()) {
const time = headers['kaserk-timestamp'], id = headers['kaserk-event-id'];
const signature = /^v1=([0-9a-f]{64})$/.exec(headers['kaserk-signature'] ?? '');
if (!Buffer.isBuffer(rawBody) || !secret || !signature || !/^\d{1,12}$/.test(time) ||
typeof id !== 'string' || !id || Math.abs(Math.floor(now / 1000) - Number(time)) > 300) throw Error('Invalid webhook');
const expected = createHmac('sha256', secret).update(time + '.' + id + '.').update(rawBody).digest();
if (!timingSafeEqual(expected,Buffer.from(signature[1],'hex'))) throw Error('Invalid webhook');
const event = JSON.parse(rawBody.toString('utf8'));
if (event.event_id !== id) throw Error('Invalid webhook');
return event;
}
{
"event_id": "00000000-0000-4000-8000-000000000001",
"type": "whatsapp.message.received",
"version": 1,
"created_at": "2026-12-01T10:00:00Z",
"resource_id": "sample_message",
"context": {
"conversation_id": "sample_chat",
"line_id": "sample_line"
},
"causation_id": null
}