Webhooks
When something happens in a shop, Kaladan sends each app that subscribed an
HTTPS POST, signed with the app’s signing secret.
Subscribing
Section titled “Subscribing”Topics are declared on an app version, each with its endpoint. Installing the version creates the subscriptions; there is no call to subscribe at runtime.
webhookSubscriptions: [ { topic: "orders/paid", endpoint: "https://anbar.example.ir/hooks" } { topic: "products/update", endpoint: "https://anbar.example.ir/hooks", includeFields: ["id", "title", "status"] }]A topic needs its scope among the version’s requestedScopes.
Topics
Section titled “Topics”| Topic | Scope | When |
|---|---|---|
orders/create | READ_ORDERS | An order was placed. Not necessarily paid. |
orders/updated | READ_ORDERS | An order changed after it was placed. |
orders/paid | READ_ORDERS | Payment was verified with the gateway: the one event that means money arrived. |
orders/cancelled | READ_ORDERS | An order was cancelled, with the reason. |
refunds/create | READ_PAYMENTS | Money was given back. |
transactions/unresolved | READ_PAYMENTS | A payment could not be verified, and reconciliation took it over. |
fulfillments/create | READ_FULFILLMENTS | A parcel was handed to a carrier. |
products/create | READ_PRODUCTS | A product was created. |
products/update | READ_PRODUCTS | A product changed; changed names which fields. |
products/delete | READ_PRODUCTS | A product was deleted. Carries only its id. |
inventory_levels/update | READ_INVENTORY | Stock moved at a location. High volume: subscribe narrowly. |
customers/create | READ_CUSTOMERS | A customer record was created. |
customers/update | READ_CUSTOMERS | A customer record changed. |
job/completed | — | A long-running job finished. Subscribe instead of polling. |
app/uninstalled | — | The merchant removed your app. Its tokens are already revoked. |
Topics every app handles
Section titled “Topics every app handles”| Topic | What to do |
|---|---|
customers/data_request | A buyer asked for what your app holds about them. Return it to the merchant within 30 days. |
customers/redact | Erase that buyer’s personal data. |
shop/redact | Erase everything you hold for the shop. Sent 48 hours after an uninstall, and withdrawn if the merchant reinstalls within that window. |
The delivery
Section titled “The delivery”POST https://anbar.example.ir/hooksContent-Type: application/json
webhook-id: evt_01JQ8Z3MK4TRXG7webhook-timestamp: 1789000000webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=X-Kaladan-Topic: orders/paidX-Kaladan-Shop: Z2lkOi8va2FsYWRhbi9TaG9wL…X-Kaladan-Sequence: 4417X-Kaladan-Delivery-Id: dlv_01JQ8Z3N2PX-Kaladan-Attempt: 1X-Kaladan-Api-Version: 2026-10The body is an envelope, described by a JSON Schema:
{ "eventId": "evt_01JQ8Z3MK4TRXG7", "topic": "orders/paid", "apiVersion": "2026-10", "occurredAt": "2026-11-09T08:12:44Z", "sequence": 4417, "shop": { "id": "…", "handle": "golnar", "primaryDomain": "golnar.ir" }, "actor": { "kind": "CUSTOMER" }, "payload": { "…": "the order, cut to your app's scopes" }, "test": false}Payloads are cut to the scopes the merchant granted: a field your app may not read is absent.
Verifying the signature
Section titled “Verifying the signature”Kaladan signs with Standard Webhooks, so any of its libraries verifies a delivery with no Kaladan-specific code. By hand:
key = base64_decode(signing secret without its "whsec_" prefix)signed = webhook-id + "." + webhook-timestamp + "." + raw bodyexpected = "v1," + base64(hmac_sha256(key, signed))import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(rawBody, headers, secret) { const id = headers['webhook-id']; const timestamp = headers['webhook-timestamp'];
// Older than five minutes, or from the future: a replay. if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64'); const expected = Buffer.from( 'v1,' + createHmac('sha256', key).update(`${id}.${timestamp}.${rawBody}`).digest('base64'), );
// One entry, or two while a secret is being rotated. return headers['webhook-signature'].split(' ').some((entry) => { const candidate = Buffer.from(entry); return candidate.length === expected.length && timingSafeEqual(candidate, expected); });}func verify(body []byte, h http.Header, secret string) bool { id, ts := h.Get("webhook-id"), h.Get("webhook-timestamp") sent, err := strconv.ParseInt(ts, 10, 64) if err != nil || math.Abs(float64(time.Now().Unix()-sent)) > 300 { return false } key, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(secret, "whsec_")) if err != nil { return false } mac := hmac.New(sha256.New, key) mac.Write([]byte(id + "." + ts + "." + string(body))) expected := []byte("v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil))) for _, entry := range strings.Fields(h.Get("webhook-signature")) { if hmac.Equal([]byte(entry), expected) { return true } } return false}- Verify the raw bytes, before parsing. Re-serialized JSON is different bytes.
- Compare in constant time. A plain
==leaks your secret one byte at a time. - Reject a timestamp more than five minutes away, and anything unverified
with
401. - During a rotation the header carries two signatures, the new secret’s first, for one day.
Answering
Section titled “Answering”- Answer
2xxwithin five seconds. Acknowledge first, then do the work: an endpoint that processes before it answers gets retried while it is still working. 410 Goneturns the subscription off for good. It is the honest way to retire an endpoint.- Anything else, a timeout, or a TLS failure is retried.
When deliveries fail
Section titled “When deliveries fail”Each delivery is retried with backoff over about two days:
1m → 5m → 15m → 45m → 2h → 5h → 12h → 24hAfter the last attempt it waits in a dead-letter queue for seven days, where you
can inspect it and replay it with webhookDeliveryReplay. If every delivery to
an endpoint fails for 24 hours, the subscription is switched off;
webhookSubscriptionReenable turns it back on and replays what is still queued.
At least once, in no global order
Section titled “At least once, in no global order”- The same event can arrive twice. Deduplicate on
webhook-id, and keep the ids for at least 48 hours. - Events can arrive out of order. Retries are per delivery, so a failure does
not hold back later events. Order by
X-Kaladan-Sequence, which rises per shop and per resource. - Quote
X-Kaladan-Delivery-Idwhen you ask for help with a delivery.