# Webhooks

A webhook makes our servers send a signed `POST` request to your server when something changes in your studio. Use it to post to a chat channel, start your own pipeline when a build goes live, or keep an internal dashboard in step, instead of polling the console.

Webhooks belong to the studio, not to one game. Owners and admins manage them on the **Webhooks** page of the developer console.

## Set one up

1. Open **Webhooks** in the console and choose **Add an endpoint**. Adding an endpoint asks you to confirm it is you with a passkey or an authenticator app; if you have neither yet, set one up first in your player account on zokogames.com (console account menu, **Settings**, then **Account**).
2. Enter an `https://` address (up to 500 characters), an optional description (up to 120 characters) and the events you want. Each event is described in the Events table below with an example payload under Payload examples. The address must follow the rules under Which addresses are accepted: public `https` on port 443, so use a tunnel while developing locally, and the console says which rule an address breaks before it saves.
3. Copy the **signing secret** (it starts with `whsec_`). It is shown once. If you lose it, use **Rotate secret**; the old one stops working at once. Rotating the secret asks for the same confirmation. A delivery your server refuses during the switch is retried, and every retry is signed with the secret current at that moment, so once your server has the new secret the retries verify (a **Send test** ping is never retried).
4. Press **Send test**. A `ping` event is delivered immediately and the result (HTTP status or error) is shown. Open **Show the exact request and response** under it to see the headers and body we sent (including the signature, so you can compare it with your own) and the status line, content type and first 1 KB of the body your server answered. That detail is not stored; it stays on screen until you leave the page.

A studio can have up to **5** endpoints. Use **Edit** on an endpoint to change its address, description or events; the signing secret stays the same, and changing the address or events asks for the same confirmation as adding one. You can pause and resume an endpoint without losing it. The console keeps the **50** most recent delivery results for the studio, with time, event, status and duration, and a delivery history that shows every event with its status, attempts, next retry and response code. The delivery history can be filtered by status (delivered, retrying, dead) and by endpoint. While an endpoint has failing deliveries, its card says how many are waiting or dead, the latest problem, and how many dead deliveries in a row switch it off.

## Events

| Event | Sent when | `data` fields |
| --- | --- | --- |
| `review.outcome` | A reviewer approved, rejected or asked for changes. | `gameId`, `gameSlug`, `gameName`, `outcome`, `note`, `rejectionReasons` (list) |
| `build.published` | A new build passed validation and was stored. It is not necessarily live: a build of a live game, and every build uploaded with an API token, stays inactive until someone activates it (watch `build.activated`). | `gameId`, `gameSlug`, `buildId`, `version` (the build number, an integer: 1, 2, 3...), `totalBytes`, `fileCount`; only for a build uploaded with an API token (CI): `uploadedBy`, an object with `type` (`api_token`), `id` and `name` of the token |
| `build.activated` | A build became the live version, including a rollback. | `gameId`, `gameSlug`, `buildId`, `version` (integer build number), `previousBuildId` |
| `feedback.replied` | Someone on your team replied to player feedback. | `gameId`, `feedbackId`, `subject`, `emailed`, `resolved` |
| `leaderboard.reset` | Leaderboard scores were reset. | `gameId`, `gameSlug`, `scope`, `season` (the running season as an ISO week string, such as `2026-W47`, also for `scope: "all"`), `deleted` (rows removed) |
| `statement.created` | The monthly payout statement for your studio was created (on the second day of the next month). Not sent for a statement that already existed. | `statementId`, `period` (`YYYY-MM`), `state`, `payableMicros`, `currency` |
| `statement.updated` | A statement was marked paid, or the portal team held or released it. | `statementId`, `change` (`paid`, `held` or `released`), `period`, `state`, `payableMicros` (`null` when the amount is settled by hand), `currency`, `paidAt` and `paidReference` (set only when `change` is `paid`), `paidMicros` and `heldBackMicros` (what was actually sent and what the new-studio holdback kept back; set only when `change` is `paid`, otherwise `null`) |
| `feedback.received` | A player sent feedback about one of your games: a report, a message to your studio or a reason after a thumbs-down. Not sent for kids games. | `feedbackId`, `gameId`, `gameSlug`, `gameName`, `kind` (`report`, `developer` or `dislike`), `subject`, `message` (up to 2,000 characters, may be empty), `gameContext` (what the game set with `setGameContext`, or `null`) |
| `experiment.finished` | A cover experiment ran its full 14 days and is ready for a winner decision. Not sent when you stop an experiment yourself. | `experimentId`, `gameId`, `gameSlug`, `gameName`, `name`, `type` (`covers`, `videos` or `both`), `startedAt`, `endedAt`, `winnerSuggested` (`variant`, `baseline` or `inconclusive` from the click-through test; `null` if it could not be computed) |
| `ping` | You pressed **Send test**. Cannot be subscribed to. | `message`, `studio` |

## The request

```http
POST /hooks/zoko HTTP/1.1
Content-Type: application/json
User-Agent: ZokoGames-Webhooks/1
X-Zoko-Event: build.published
X-Zoko-Delivery: 6f1c2d1e-8a54-4e0b-9a39-0f4c9a5b7d10
X-Zoko-Event-Id: 6f1c2d1e-8a54-4e0b-9a39-0f4c9a5b7d10
X-Zoko-Attempt: 1
X-Zoko-Signature: t=1763424000,v1=5b1f...c9
```

```json
{
  "id": "6f1c2d1e-8a54-4e0b-9a39-0f4c9a5b7d10",
  "event": "build.published",
  "createdAt": "2026-11-18T00:00:00.000Z",
  "studioId": "…",
  "data": { "gameId": "…", "gameSlug": "my-game", "buildId": "…", "version": 3, "totalBytes": 18400000, "fileCount": 212 }
}
```

`id` is the **event id**. It is the same as the `X-Zoko-Event-Id` header (and the older `X-Zoko-Delivery` header, kept for compatibility), it is unique per event and per endpoint (two endpoints subscribed to one event get different ids), and it stays the same on every retry and manual redelivery. `X-Zoko-Attempt` is the attempt number, starting at 1. The signature is made again for every attempt, so `t` is always fresh.

## Payload examples

Every request has the envelope shown above. These are the `data` objects, one per event. Values are examples.

```json
// review.outcome: outcome is changes_requested, rejected, basic_launch, full_launch or update_approved
{ "gameId": "…", "gameSlug": "my-game", "gameName": "My Game", "outcome": "changes_requested", "note": "Please fix the loading screen.", "rejectionReasons": [] }

// build.published
{ "gameId": "…", "gameSlug": "my-game", "buildId": "…", "version": 3, "totalBytes": 18400000, "fileCount": 212 }

// build.activated (previousBuildId is null for the first live build)
{ "gameId": "…", "gameSlug": "my-game", "buildId": "…", "version": 3, "previousBuildId": "…" }

// feedback.replied
{ "gameId": "…", "feedbackId": "…", "subject": "Lost progress", "emailed": true, "resolved": false }

// leaderboard.reset (scope is season or all)
{ "gameId": "…", "gameSlug": "my-game", "scope": "season", "season": "2026-W47", "deleted": 1280 }

// statement.created
{ "statementId": "…", "period": "2026-10", "state": "invoiced", "payableMicros": 1250000, "currency": "USD" }

// statement.updated
{ "statementId": "…", "change": "paid", "period": "2026-10", "state": "paid", "payableMicros": 1250000, "currency": "USD", "paidAt": "2026-12-20T09:00:00.000Z", "paidReference": "TR-1042", "paidMicros": 1250000, "heldBackMicros": 0 }

// statement.updated for a paid statement of a new studio: payableMicros is the full amount, paidMicros what was sent, heldBackMicros what the holdback kept back
{ "statementId": "…", "change": "paid", "period": "2026-10", "state": "paid", "payableMicros": 200000000, "currency": "USD", "paidAt": "2026-12-20T09:00:00.000Z", "paidReference": "0x5f2c…", "paidMicros": 160000000, "heldBackMicros": 40000000 }

// statement.updated for a statement whose amount is settled by hand (payableMicros is null, never 0)
{ "statementId": "…", "change": "held", "period": "2026-10", "state": "held", "payableMicros": null, "currency": "USD", "paidAt": null, "paidReference": null, "paidMicros": null, "heldBackMicros": null }

// feedback.received
{ "feedbackId": "…", "gameId": "…", "gameSlug": "my-game", "gameName": "My Game", "kind": "dislike", "subject": "Dislike: Too many ads", "message": "", "gameContext": null }

// experiment.finished
{ "experimentId": "…", "gameId": "…", "gameSlug": "my-game", "gameName": "My Game", "name": "Close-up cover", "type": "covers", "startedAt": "2026-11-05T00:00:00.000Z", "endedAt": "2026-11-19T00:00:00.000Z", "winnerSuggested": "variant" }

// ping
{ "message": "Test delivery from the developer console", "studio": "My Studio" }
```

The block above is annotated for reading; real payloads are plain JSON without comments.

The `note` of `review.outcome` and the `subject` and `message` of `feedback.received` and `feedback.replied` are untrusted plain text written by people (they can contain link addresses as visible text): escape them before showing them in HTML and never treat them as markup.

Fields are stable: new fields may be added to an event's `data` (appended at the end, as `paidMicros` and `heldBackMicros` were on 20 November 2026), and existing ones are not renamed or removed. Ignore fields you do not know, and never reject an event because it has one: a delivery you answer with an error is retried, and repeated dead deliveries switch the endpoint off.

## Verify the signature

Anyone who learns your URL can post to it, so check every request. The `X-Zoko-Signature` header has two parts:

- `t`: the time we signed, in Unix seconds.
- `v1`: the lowercase hex **HMAC-SHA256** of the text `"<t>.<raw body>"`, keyed with your endpoint secret (the whole `whsec_...` string).

Steps: read the **raw** request body before any JSON parsing, build `t + "." + body`, compute the HMAC, compare it to `v1` in constant time, and reject a `t` that is more than five minutes from your clock to stop replays.

:::tabs
== Node.js
```js
import { createHmac, timingSafeEqual } from "node:crypto";
import express from "express";

const SECRET = process.env.ZOKO_WEBHOOK_SECRET;
const app = express();

app.post("/hooks/zoko", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("x-zoko-signature") ?? "";
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
  const t = Number(parts.t);
  if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > 300) return res.sendStatus(400);

  const expected = createHmac("sha256", SECRET).update(`${t}.`).update(req.body).digest("hex");
  const given = Buffer.from(parts.v1 ?? "", "hex");
  const want = Buffer.from(expected, "hex");
  if (given.length !== want.length || !timingSafeEqual(given, want)) return res.sendStatus(401);

  const event = JSON.parse(req.body.toString("utf8"));
  // de-duplicate on event.id, then handle event.event
  res.sendStatus(204);
});
```
== Python
```python
import hashlib, hmac, os, time
from flask import Flask, request, abort

SECRET = os.environ["ZOKO_WEBHOOK_SECRET"].encode()
app = Flask(__name__)

@app.post("/hooks/zoko")
def zoko_hook():
    header = request.headers.get("X-Zoko-Signature", "")
    parts = dict(p.split("=", 1) for p in header.split(",") if "=" in p)
    try:
        t = int(parts["t"])
    except (KeyError, ValueError):
        abort(400)
    if abs(time.time() - t) > 300:
        abort(400)

    body = request.get_data()  # raw bytes, before any JSON parsing
    expected = hmac.new(SECRET, f"{t}.".encode() + body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, parts.get("v1", "")):
        abort(401)

    event = request.get_json()
    # de-duplicate on event["id"], then handle event["event"]
    return "", 204
```
:::

## Delivery, retries and timeouts

- Every event is queued first and sent once straight away. If that attempt fails, we retry up to **6** more times after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours (each wait varies by up to 20 percent so retries do not arrive in a burst). These are minimum waits: the retry job runs every 15 minutes, so a retry can arrive up to 15 minutes after its wait ends. After the last attempt the delivery is marked **dead**.
- Your server must answer with a `2xx` status within **5 seconds**. Anything else, including a timeout, counts as failed and is retried. Do the real work after you respond.
- Redirects are **not followed**. Answer on the exact URL you registered.
- Deliveries are sent after the action that triggered them finishes, and a broken endpoint never blocks that action.
- Order is not guaranteed, and a retry can arrive after a newer event. Use `createdAt` to order events.
- Retries for an endpoint are also sent when a new event for that endpoint is dispatched, so a busy studio sees retries sooner.
- Only the first 64 KB of your response is read, and an event larger than 64 KB is sent with `"data": { "truncated": true }`. Every payload documented here is far smaller.
- The `ping` from **Send test** is sent once, is not queued and is never retried. Its result appears at once in the console.
- Delivered events are kept in the history for 30 days, dead ones for 90 days.

### De-duplicate on the event id

A retry or a redelivery sends the same event again, and a timeout does not tell us whether your server processed it. Delivery is therefore **at least once**: store the `X-Zoko-Event-Id` of every event you handled, and when you see one again answer `2xx` without repeating the work. Keyed on that stable id, your handler is idempotent: handling the same event twice has the same effect as handling it once. Do not use a hash of the body as the key: a retry carries the same fields and values, but the fields can come in a different order than in the first attempt (the signature is computed over the bytes of each attempt, so verify each one as received).

### Automatic switch-off

After **5** dead deliveries in a row, with no successful delivery in between, the endpoint is switched off and the studio's owners and admins get a notification. The console shows the endpoint as switched off. That in-app notice is the only message sent (no email), so check the console if events stop arriving. Fix your server and press **Re-enable**; events that were still waiting are then sent. A person pausing an endpoint is not counted as a failure.

A delivery only counts as dead after its last retry, a day and a half after the event, so an endpoint that is down is switched off after five such events, and one that gets a few events a day takes days to reach that point. Pressing **Re-enable** or a delivery that succeeds starts the count from zero.

### Events while an endpoint is paused or switched off

An endpoint that is paused or switched off receives **nothing new**: an event that happens meanwhile is not stored for it and is not sent when you resume. Only deliveries that were already queued before it stopped (waiting for a retry) are sent after **Re-enable**, and a dead one can be sent with **Redeliver** once the endpoint is on. To catch up after a break, read the current state from the [developer API](https://docs.zokogames.com/guides/developer-api) (for example `GET /api/v1/games/{id}/builds`, `GET /api/v1/statements` or `GET /api/v1/games/{id}/feedback`) instead of waiting for events that were never queued.

### Redeliver

In the delivery history, a delivery that is retrying or dead has a **Redeliver** button (owners and admins). It sends the event again immediately with the same event id and a fresh set of retries. The endpoint must be enabled.

## Which addresses are accepted

To protect everyone, endpoints must be reachable on the public internet:

- `https` only, on the default port 443, with no username or password in the URL.
- No `localhost`, `.local`, `.internal` or single-label host names.
- The host name must resolve, and **every** address it resolves to must be public. Private, loopback, link-local, carrier-grade NAT and multicast ranges are refused.
- The check runs again before each delivery, so a name that later points at a private address stops receiving events.

For local development, expose your dev server through a public HTTPS tunnel.

## Troubleshooting

| Log shows | Meaning |
| --- | --- |
| `Timed out after 5 seconds` | Respond first, work later. |
| A `3xx` status | Redirects are not followed; register the final URL. |
| `4xx` / `5xx` | Your server refused or failed; check the signature code and the raw-body handling. |
| `The address must be reachable on the public internet.` | The host resolves to a private address. |
| `That host name does not resolve.` | DNS has no answer yet. |

Signature mismatches almost always come from parsing and re-serialising the JSON before hashing. Hash the exact bytes you received.

Webhook signatures use your endpoint secret. The public keys at `/.well-known/jwks.json` are for [purchase tokens](https://docs.zokogames.com/sdk/purchases#verifying-a-purchase-on-your-server) and for player tokens from `getUserToken` ([verifying on your server](https://docs.zokogames.com/sdk/user#verifying-on-your-server)); they never sign a webhook. Purchases have no webhook; verify the purchase token instead.

`payableMicros` is in millionths of the statement currency (`1250000` is 1.25). See [payouts](https://docs.zokogames.com/business/payouts) for the states. For the notifications your team receives in the console, by push and by email, see [notifications](https://docs.zokogames.com/guides/notifications).

`payableMicros` is `null` when the statement's amount is outside the range we can state exactly: beyond 9,007,199,254,740,991 micros (about 9 billion units of the currency), positive or negative. We never round such an amount. The portal team settles that statement with you by hand, and the [developer API](https://docs.zokogames.com/guides/developer-api) answers `409 amount_unsafe` for it. Do not treat `null` as `0`: the statement is not empty, its amount is just not in the payload. Show it as needing attention, and contact developer support if you need the figure.

`paidMicros` and `heldBackMicros` were added on 20 November 2026; the other fields did not change. When `change` is `paid`, `paidMicros` is the amount actually sent to you for this statement and `heldBackMicros` is the part the new-studio holdback kept back from it (`0` when no holdback applied), both taken from the payment record and in millionths of the statement currency. `payableMicros` keeps its meaning, the full payable amount: a statement of 200.00 paid with a 20% holdback has `payableMicros: 200000000`, `paidMicros: 160000000` and `heldBackMicros: 40000000`. Payouts are sent in whole cents, so `paidMicros + heldBackMicros` can be lower than `payableMicros` by less than one cent. If a payment arrived short and the portal team accepted it, `paidMicros` is the amount that arrived and the difference is added to your next statement. If more arrived than was sent for, `paidMicros` is that higher amount, so `paidMicros + heldBackMicros` can exceed `payableMicros`; the extra is not taken back automatically. A Stripe transfer reversed after payment sends no new event: the `statement.updated` you received keeps the amount sent, and the portal team settles the reversal with you. In the developer API, `paid_minor` stays the amount sent after a partial reversal and becomes `null` after a full one. The held-back amount is paid back later as a holdback line on a newer statement, which you see in that statement's `statement.created`; no separate event is sent for it. Both fields are `null` when `change` is `held` or `released`, when the amount cannot be stated exactly (as for `payableMicros`), and when the payment record cannot be read reliably (for example an amount in another currency). Do not treat `null` as `0`.

## Related

- [Statements, PDFs and sandbox payouts](https://docs.zokogames.com/guides/statements-and-pdf) for `statement.created` and `statement.updated`.
- [Player feedback emails and dislike reasons](https://docs.zokogames.com/guides/feedback-emails) for `feedback.received` and `feedback.replied`.
- [Artwork experiments](https://docs.zokogames.com/guides/artwork-experiments) for `experiment.finished`.
