Examples
Next.js webhook handler
App Router route that verifies signatures and dispatches events
Example App Router route that verifies Wocha webhook signatures and dispatches by event type.
Setup
Add your signing secret to .env.local:
Route handler
Create app/api/webhooks/wocha/route.ts:
Important notes
- Use the raw body — call
req.text()before parsing JSON. Next.js must not pre-parse the body for this route. - Return 2xx quickly — queue heavy work to a background job; Wocha retries on timeout.
- Deduplicate — track processed
event_idoridempotency_keyvalues to handle at-least-once delivery. - Legacy event names — some events arrive as
org.*; handle both forms or normalize before switching.