OSuiteStart free trial

Webhooks

Your server told of invoices posted, payments received and checkouts paid or closed, signed.

Setting them up

Webhooks (Connections › Webhooks) tell your server when invoices are posted (invoice.posted), cancelled (invoice.cancelled) or given another number (invoice.renumbered, which carries previousNumber: find the sale by it and take the new number and PDF), payments received, a checkout is paid (checkout.paid) or closes unpaid (checkout.expired), and a proforma is paid and invoiced (proforma.invoiced), signed with your webhook secret. The events: invoice.posted, invoice.cancelled, invoice.renumbered, payment.received, checkout.paid, checkout.expired, proforma.invoiced; a proforma that expires or is cancelled sends none (you know its validUntil, and cancel it yourself). Each is a POST with the JSON body { id, event, occurredAt, data }: data is the invoice, payment or proforma as OSuite holds it, with OSuite’s own field names (totalAmount, customerId: { id, display }), not the API’s; a checkout event carries the checkout. Before acting, fetch the document through the API: an invoice or proforma by data.id; for payment.received, which carries the payment itself (no endpoint of its own), the invoice each of its lines pays, lines[].invoiceId.id. A call that does not get a 2xx is tried again 5 more times over about 50 minutes, with the same event id and occurredAt but a fresh X-OSuite-Timestamp, so skip one you have already handled, and judge a call’s age by X-OSuite-Timestamp, never by occurredAt. A checkout event carries id, status, website, reference, invoiceId, invoiceNumber, total, currency, paidAt and expiresAt. A checkout for a proforma sends proforma.invoiced, not checkout.paid. openapi.json gives each event’s schema: the fields of data named there are promised, others may change; amounts in data are decimals as text, such as "1416.00".

Each call carries X-OSuite-Timestamp and X-OSuite-Signature: sha256=<hex HMAC-SHA256 of "<timestamp>.<body>"> keyed with the webhook’s secret. Refuse a call whose X-OSuite-Timestamp is more than 5 minutes old: it is new on every try and covered by the signature. Do not judge age by occurredAt in the body: that is when it happened in OSuite, the same on every retry, so a retry long after still carries the first time.

Checking one

              import { createHmac, timingSafeEqual } from 'node:crypto';
function fromOSuite(req, rawBody, secret) {
  const ts = req.get('x-osuite-timestamp');
  if (!ts || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
  const want = `sha256=${createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex')}`;
  const got = req.get('x-osuite-signature') ?? '';
  return got.length === want.length && timingSafeEqual(Buffer.from(got), Buffer.from(want));
}
            

Only yours

Choose your website under Only events from when adding the webhook (Connections › Webhooks): it then hears only of the invoices, payments, proformas and checkouts your website made, including invoices reissued or renumbered in OSuite, which keep their website. Left as Everything in OSuite, it hears of every invoice, payment and proforma in OSuite: act only on yours. An invoice your website made has data.apiSource set to your token’s name (null for one made in OSuite); a token’s name cannot be changed, and a replaced token keeps it. Fetching any other with your token answers 404: answer the webhook 2xx and skip it, or it is tried again 5 more times.

Trying your handler before going live

Trying your handler before going live, under Connections › Webhooks: Send a test sends the event ping, { message }, to check your signature code. Send a sample sends the latest real event of the kind you choose, built as it was delivered and signed, under an id starting evt_sample_; an event that has not happened in this OSuite yet has none (Nothing to send yet). A sample is a real past event: handle one starting evt_sample_ as a dry run (check the signature, read it, fetch the document, log what you would do, answer 2xx) and change nothing, or it would mark a real order paid twice or cancel a live one.

Also as Markdown. See the API reference for every field.