Munim Technologies

Webhooks and events

Signed webhooks, every event type, retries, and the events feed for staying in sync.

Add an endpoint

Add one in the dashboard under Developers → Webhooks, or with the API. The signing secret (whsec_…) is shown once: store it as MUNIM_BILLING_WEBHOOK_SECRET. Test and live endpoints are separate and have different secrets.

Request
curl https://billing-sandbox-api.munimtech.com/v1/webhook_endpoints \
  -H "Authorization: Bearer $MUNIM_BILLING_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/webhooks/munim",
       "events": ["transaction.completed", "subscription.canceled"]}'
Response
{
  "id": "whk_…",
  "url": "https://example.com/webhooks/munim",
  "events": ["transaction.completed", "subscription.canceled"],
  "project_id": null,
  "secret": "whsec_…",
  "created_at": 1764460800000
}

Leave out events (or send an empty list) to get all of them. POST /v1/webhook_endpoints/:id/test sends a ping event; GET /v1/webhook_endpoints shows each endpoint’s recent deliveries. Add project_id to only get one project’s events.

Verify and handle events

verifyWebhook checks the signature in constant time, rejects timestamps more than five minutes off, and returns a typed event. Pass the raw request body, before any JSON parsing.

// app/webhooks/munim/route.ts
import { verifyWebhook } from 'munim-billing'

export async function POST(request: Request) {
  let event
  try {
    event = await verifyWebhook(
      await request.text(),                      // the raw body
      request.headers.get('Munim-Signature'),
      process.env.MUNIM_BILLING_WEBHOOK_SECRET!,
    )
  } catch {
    return new Response('bad signature', { status: 400 })
  }

  switch (event.type) {
    case 'transaction.completed':
      await grantAccess(event.data.object)
      break
    case 'subscription.canceled':
      await revokeAtPeriodEnd(event.data.object)
      break
  }
  return new Response('ok')
}

Each delivery is a POST of an event:

Event
{
  "id": "evt_…",
  "object": "event",
  "type": "transaction.completed",
  "created_at": 1764460800000,
  "project_id": "prj_…",
  "data": {
    "object": { "id": "txn_…", "object": "transaction", "amount": 999, "fee": 100, "net": 899, … }
  }
}
Headers
Munim-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256(secret, `${t}.${rawBody}`)>
Munim-Event-Id: evt_…

Not using the SDK? Compute HMAC-SHA256 of `${t}.${rawBody}` with the whole secret string (whsec_ included) as the key, hex-encode it, and compare it with each v1= value. A header with several v1= values passes when any one matches.

Event types

Eventdata.objectWhen
checkout.completedCheckoutA checkout was paid.
transaction.completedTransactionA payment went through: a one-time sale, a new subscription or a renewal.
transaction.refundedTransactionAll or part of a payment was refunded.
transaction.disputedTransactionThe customer opened a chargeback.
subscription.createdSubscriptionA subscription started.
subscription.updatedSubscriptionIts status, period or cancel-at-period-end changed.
subscription.canceledSubscriptionIt ended or was canceled.
payout.paidPayoutA payout reached your bank.
payout.failedPayoutA payout failed; see failure_reason.
report.readyReportAn export finished. download_url is null here; fetch the report for one.

Retries and duplicates

Answer with a 2xx within 10 seconds. Failed deliveries are retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours and 24 hours.

The same event can arrive more than once. Use Munim-Event-Id (or event.id) to skip ones you’ve handled. Events can also arrive out of order; when it matters, fetch the object for its latest state.

The events feed

Every event webhooks send is also in GET /v1/events. With after it returns the events since that one, oldest first: the simplest way to keep an internal tool or warehouse in sync without running a webhook server. Save the last id you processed and pass it next time.

# The first time: everything from the start, oldest first
curl "https://billing-sandbox-api.munimtech.com/v1/events?after=start&limit=100" -H "Authorization: Bearer $MUNIM_BILLING_SECRET_KEY"

# Every time after: what happened since the last one you saw
curl "https://billing-sandbox-api.munimtech.com/v1/events?after=evt_…" -H "Authorization: Bearer $MUNIM_BILLING_SECRET_KEY"

Filter with type (comma-separated) and project_id; limit is 1 to 100, default 50. Without after, the list is newest first and pages with cursor. Read-only keys can read it.

Payout and report events belong to the whole account, so project-filtered webhooks and feeds get them too.