API Reference
Webhooks
How webhook events reach your server — the request, verifying the signature, responding, retries and duplicates.
Webhooks push events to your server instead of you polling for them. When an
event is triggered — a wallet balance changes, a customer is added, a
subscription renews, an invoice is paid, a card is refunded — Clocknext sends an HTTP POST with a JSON body to every endpoint
subscribed to it, signed with that endpoint's secret.
You register endpoints, pick their events, and copy their signing secret in Settings → Webhooks. There is no API for managing endpoints yet — this page covers receiving events.
Events
Each event has its own page with its full payload, under Webhooks in the API reference. You pick the events for each endpoint in Settings.
Wallet
| Event | Triggered when |
|---|---|
wallet.balance.update | A customer's Wallet balance increases or decreases, except through usage signals. |
wallet.balance.drop | A customer's Wallet balance falls from above their low-balance threshold, or the endpoint's threshold if they have none, to at or below it. The threshold is in USD or a percentage of the plan's Wallet amount per cycle. |
Both events watch the customer's ordinary Wallet only. Changes to the Reserved Wallet don't trigger them.
The low-balance threshold behind wallet.balance.drop is either a USD amount or
a percentage (0 to 100) of the plan's Wallet amount per cycle. The event's
data carries threshold for a USD level, or threshold_percentage for a
percentage level: exactly one of the two is present. A percentage level applies
to advance-billed Wallets only; with no active plan Wallet amount, it sends
nothing.
When the org has the Reserved Wallet on, wallet.balance.drop also carries
reserved_balance: the Reserved Wallet's live balance, in USD. The threshold is
still checked on the main Wallet only.
Not triggered by usage signals
wallet.balance.update isn't triggered when a usage signal charges the
Wallet. To read a balance, call
Get a customer's balances.
wallet.balance.drop is still triggered when a signal takes the balance to
the low-balance threshold.
Customer
| Event | Triggered when |
|---|---|
customer.created | A customer is added, in the dashboard or through the API. |
customer.updated | A customer's details change. updated_fields names the fields that changed. |
customer.archived | A customer is archived. |
customer.restored | An archived customer is restored. |
Subscription
| Event | Triggered when |
|---|---|
subscription.created | A plan is recorded for a customer. It starts once it is due. |
subscription.activated | A subscription starts: its entitlements are live. |
subscription.renewed | A subscription moves on to its next billing period. |
subscription.on_hold | A renewal invoice is unpaid. The customer keeps last period's entitlements until it is paid or the hold ends. |
subscription.resumed | A held renewal is paid and the hold clears. |
subscription.cancellation_scheduled | A subscription is marked to end at the end of its paid period. It keeps working until then. |
subscription.cancelled | A subscription ends. reason is CANCELLED, PLAN_CHANGE, HOLD_EXPIRED or UNPAID. |
Package
| Event | Triggered when |
|---|---|
package.added | A package on a subscription becomes active: its invoice is paid or recorded as paid. |
package.removal_scheduled | A package is removed with atPeriodEnd: true. It keeps working until the end of the plan's billing cycle. |
package.ended | A package ends. ended_reason is REMOVED, INVOICE_VOIDED, PLAN_CHANGED or SUBSCRIPTION_CANCELLED. |
Invoice
| Event | Triggered when |
|---|---|
invoice.created | An invoice is issued. A package attach invoice carries package_invoice. |
invoice.paid | An invoice is marked paid, by a payment recorded by hand or through a payment gateway. |
invoice.voided | An invoice is voided, by hand or automatically. |
Payment
| Event | Triggered when |
|---|---|
payment.succeeded | Money arrives: an invoice is paid, or the customer buys something in the customer portal. |
payment.failed | An automatic card charge for an invoice is refused (declined, or the bank asks to confirm it). |
Credit note
| Event | Triggered when |
|---|---|
credit_note.created | A credit note is issued on an invoice: by hand, through the API, by a cancel with a refund, or by a plan change. |
credit_note.voided | A credit note is voided while its invoice is still open. The invoice owes the amount again. |
A credit note is a document; it moves no money by itself. To know when an
invoice is credited in full (for example, to take access away), compare
invoice.credit_notes_amount with invoice.amount in credit_note.created:
when they are equal, every cent of the invoice is credited. That does not mean
the money is back on the card — see the refund events below.
Refund
| Event | Triggered when |
|---|---|
refund.created | A card refund is asked of the payment gateway. The money is not on the card yet. |
refund.succeeded | The payment gateway confirms the refund to the card. |
refund.failed | The payment gateway fails or rejects a card refund. The money goes into the customer's invoice balance. |
Only refund.succeeded means the money reached the card. refund.failed has
status FAILED or REJECTED_IN_GATEWAY_REVIEW (Paddle's review said no);
use status to decide and failure_reason to show. After a failure the money
is in the customer's invoice balance, so you can ask for the refund again or
tell the customer.
Tick the new events on existing endpoints
An endpoint gets the credit note and refund events only after you tick them in Settings → Webhooks. Endpoints that existed before these events don't get them on their own.
Events that come together
One change can trigger more than one event. Each event has its own id.
- An invoice is paid.
invoice.paid, thenpayment.succeededwhen the invoice was for more than 0. A paid renewal that was on hold also triggerssubscription.resumed. - A subscription moves on to its next period.
subscription.renewed. When the renewal invoice is not paid yet,subscription.on_holdfollows. The renewal invoice has its owninvoice.createdwhen it is issued. - An invoice is voided and its subscription ends.
invoice.voidedandsubscription.cancelled. When many invoices are voided at the same time, each invoice gets its owninvoice.voided. - A portal buy (a top-up, credits, outcomes or units).
payment.succeededwithitemset andinvoicenull. A plan upgrade in the portal pays an invoice instead, so it triggersinvoice.paidandpayment.succeededwithinvoiceset. - Packages are added to a subscription.
invoice.createdfor their invoice. When it is paid,invoice.paid,payment.succeededand onepackage.addedfor each package. - A refused card.
payment.failedis triggered once for each invoice and card. Automatic retries with the same card do not trigger it again. - A credit note that refunds the card.
credit_note.created, thenrefund.created. When the gateway answers at once,refund.succeededorrefund.failedfollows. A credit note that goes to the invoice balance or lowers an open invoice triggers no refund event. A credit note that covers an open invoice in full also triggersinvoice.paidandpayment.succeeded, aftercredit_note.created. - A refund split over 2 card payments. A refund from the invoice balance
that goes back to 2 card payments triggers 2
refund.created, each with its own refundid,amountand invoice. Each then gets its ownrefund.succeededorrefund.failed. - A refund that fails late. A gateway can report a failure after the
refund succeeded (Stripe up to 30 days later, or a Paddle reversal). Then
refund.failedfollowsrefund.succeededfor the same refund.refund.failedis final: nothing follows it.
All amounts are in USD (currency_code: "usd"). Invoice and payment events also
have display_amount and display_currency_code: the amount in the currency
the customer pays in. Refund events have charged_amount_minor and
charged_currency_code instead: what goes back to the card, in whole minor
units of the currency it was charged in.
The request
Every event is sent the same way, with three headers and the same envelope —
only data differs between events:
POST /webhooks/clocknext HTTP/1.1
Content-Type: application/json
X-Clocknext-Signature: t=1791367200,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
X-Clocknext-Event-Id: evt_3f9a1c6e8b2d4f7a9c0e1b2d3f4a5b6c
X-Clocknext-Event-Type: wallet.balance.drop
{
"id": "evt_3f9a1c6e8b2d4f7a9c0e1b2d3f4a5b6c",
"event_type": "wallet.balance.drop",
"triggered_at": "2026-10-07T14:02:51.093Z",
"data": { … }
}X-Clocknext-Event-Id and X-Clocknext-Event-Type repeat the body's id and
event_type, so you can route a request before parsing it.
Verify the signature
Check every request before you trust it. The signature is an HMAC-SHA256,
keyed with the endpoint's full signing secret (including the whsec_ prefix),
over the string ${t}.${rawBody} — the timestamp, a dot, and the raw
request body exactly as received.
- Split
X-Clocknext-Signatureon,and read thetandv1values. - Compute
HMAC-SHA256(secret, t + "." + rawBody)as lowercase hex. - Compare it to
v1with a constant-time comparison. - Reject requests whose
tis too old (for example, more than 5 minutes) to block replays.
Sign the raw body. Parsing the JSON and re-serialising it changes the bytes
and the signature won't match. Each sample below does the same steps. In
Node.js the @clocknext/sdk package does them for you; the other languages write
them out. Pick your language:
import express from "express";
import { constructWebhookEvent, WebhookSignatureError } from "@clocknext/sdk";
const app = express();
const SECRET = process.env.CLOCKNEXT_WEBHOOK_SECRET!; // whsec_…
// express.raw keeps the body as bytes so the signature can be checked.
app.post("/webhooks/clocknext", express.raw({ type: "application/json" }), (req, res) => {
let event;
try {
// Checks the signature and rejects events older than 5 minutes.
event = constructWebhookEvent(req.body, req.header("x-clocknext-signature"), SECRET);
} catch (err) {
if (err instanceof WebhookSignatureError) return res.status(400).send("Invalid signature");
throw err;
}
switch (event.event_type) {
case "wallet.balance.update":
// e.g. record the top-up or adjustment
break;
case "wallet.balance.drop":
// e.g. email the customer to top up
break;
case "invoice.paid":
// e.g. mark event.data.invoice.number paid in your own books
break;
case "subscription.cancelled":
// e.g. turn off access; event.data.reason says why it ended
break;
case "credit_note.created":
// e.g. take access away when event.data.invoice.credit_notes_amount equals event.data.invoice.amount
break;
case "refund.failed":
// e.g. ask for the refund again, or tell the customer; event.data.refund.status says why
break;
}
res.sendStatus(200);
});
app.listen(3000);Respond, retries, and duplicates
- Answer with any
2xxwithin 5 seconds. Anything else — a non-2xx status, a timeout, or a connection error — counts as a failed delivery. Do slow work after you respond. - Failed deliveries are retried automatically, 2 more times: after 30 seconds and after 2 minutes. Every attempt, and the HTTP status your server answered, is listed under Message Attempts on the endpoint's page, where you can also retry a failed delivery by hand.
- The same event can arrive more than once. Retries reuse the event's
id(andX-Clocknext-Event-Id), so record the ids you've handled and skip repeats. - Events can arrive out of order. Use
triggered_atand the values indata(a balance, astatus) rather than arrival order. For example, accept arefund.succeededfor a refund whoserefund.createdyou haven't seen yet. For the current state, read it from the API — for example Get customer balances or Get a subscription. - Disabled endpoints get nothing. Events triggered while an endpoint is disabled are dropped, not saved for later.
Rotating the secret
Rotating an endpoint's secret in Settings takes effect immediately — every delivery after that, including retries of earlier events, is signed with the new secret. Update your server's secret straight away.
Your own customer ids
Give a customer an externalId — the id your product already uses — and name it by that instead of ours.
Record credit POST
Records one LLM call against a credit, named by `agentKey` (matched exactly, case included). The credit must be on the customer's plan, or covered by a composite on it. The price comes from the model's rates. Answers `202`; a signal that can't be counted stays `PENDING`. See [List raw signals](/docs/api-reference/signals/eventsListSignals).