---
title: Webhooks
section: API
order: 5
---

# Webhooks

Get the game's moments pushed to your own server as they happen: a Discord bot that posts "Blue took
ALPHA", a siren at the base when a side runs out of tickets, a club page that keeps a live log. No
need to keep a connection open or to poll.

A webhook belongs to the **key that registers it** and hears exactly what that key may read:

| Key | Hears |
|---|---|
| Team key (`gt_team_`) | The events of the [team view](team.md): everything meant for that team or for everyone. Never another side's, never the game master's own, never chat. |
| Dashboard key (`gt_dash_`) | The events of the [dashboard](dashboard.md): zones taken and lost, hot zones, hold bonuses, delivered items, a side out of tickets, the game paused and resumed, UAVs and EMPs. Never who did it. When the game master runs the dashboard behind (a delay of N minutes), each event arrives N minutes late, like on the dashboard. |

Revoke the key and its webhooks go quiet. At most 5 webhooks per key.

## First, get a key

1. Sign in on [gridtac.com](https://gridtac.com). Keys need **two-factor authentication** (or an
   account that signs in only with Google or Apple): turn it on in **Account** first if it is off.
2. Open **API & hardware** in the account menu and choose the kind: **"Team: one team's board or bot"** for one side's events
   (you must be its commander, or the game master) or **"Dashboard: a spectator screen"** for the
   public picture (game master only). Pick the game (and the team), give the key a name such as
   "Discord bot", and press **Create key**.
3. Copy the key (`gt_team_…` or `gt_dash_…`) right away: it is shown only once. Keep it out of your
   code repository.

More on keys and their limits: [Authentication](authentication.md).

## Register

```http
POST /api/v1/webhooks
Authorization: Bearer gt_team_…
Content-Type: application/json

{ "url": "https://bot.example.com/gridtac", "events": ["zone_captured", "zone_neutralised"] }
```

`events` is optional: leave it out to get every type the key may hear. The answer carries the
webhook and its **secret** (`whsec_…`). It is shown only this once: store it with your receiver.

The URL must be `https://` on the public internet. Private, loopback, link-local and reserved
addresses are refused (`url_not_allowed`), also if a name later starts pointing at one. Redirects are
not followed.

## What arrives

```http
POST /gridtac
Content-Type: application/json
User-Agent: GridTac-Webhooks/1
GridTac-Event: zone_captured
GridTac-Webhook-Id: 7b0c…
GridTac-Delivery-Id: 3f1e…
GridTac-Signature: t=1794041632,v1=5d2c…

{
  "deliveryId": "3f1e…",
  "webhookId": "7b0c…",
  "gameId": "a91f…",
  "event": { "id": "c0de…", "type": "zone_captured", "at": "2026-11-14T10:38:55.000Z", "summary": "Blue took ALPHA", "actor": "BLUE2" }
}
```

`actor` is there for a team key only. Answer with any `2xx` within 5 seconds; do the slow work after
you have answered. Use `event.id` to ignore a repeat: a delivery can arrive twice if your answer was
lost on the way back.

## Check the signature

Every delivery is signed. Before trusting one, compute HMAC-SHA256 over `<t>.<raw body>` with your
secret and compare it to `v1`, and refuse a `t` more than five minutes from your clock: that stops
someone from replaying an old delivery.

```js
import { createHmac, timingSafeEqual } from 'node:crypto';

function verify(secret, header, rawBody) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const t = Number(parts.t);
  if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const expected = Buffer.from(createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex'));
  const given = Buffer.from(parts.v1 ?? '');
  return expected.length === given.length && timingSafeEqual(expected, given);
}
```

Use the raw body exactly as it arrived, before any JSON parsing.

## Retries and the delivery log

A delivery that does not get a `2xx` is tried again after 10 seconds, 1 minute, 5 minutes,
30 minutes, 2 hours and 6 hours, then marked failed. After 50 failed deliveries in a row the webhook
is switched off; its `status` says `disabled` and `disabledReason` says why. Register it again once
your receiver works.

| Call | What it does |
|---|---|
| `GET /api/v1/webhooks` | This key's webhooks, never their secrets. |
| `GET /api/v1/webhooks/{id}/deliveries` | The latest 50 deliveries with each outcome: your HTTP status, or why your server could not be reached. Kept for 14 days. |
| `POST /api/v1/webhooks/{id}/ping` | A signed `ping` delivery, to test your receiver. |
| `DELETE /api/v1/webhooks/{id}` | Stops it, retries included. |

These calls count against the key's `manage` budget, 30 a minute
([rate limits](authentication.md#rate-limits)). Events start from the moment the webhook is
registered; earlier events are in the [team view](team.md) and the [dashboard](dashboard.md).
