# Webhooks

A webhook sends each change in projqo to an address of yours, as it happens, instead of your code asking again and again. Deliveries are signed, retried when your address doesn't answer, and logged for 30 days.

## Subscribing

An app subscribes with the API, at `/api/v1/orgs/{org}/webhooks`, with the scope `webhooks:manage`:

- the **address** that receives the deliveries;
- the **events** it wants;
- optionally, the **projects** it wants them from, or a **task query** in the [query language](/guides/query-language/) that a task must match.

To subscribe to an event, the token also needs the read scope of what the event carries: an app without `docs:read` can't subscribe to page events.

A subscription made by an app belongs to that app's connection: it goes when the person disconnects the app. Organisation admins see it on their Webhooks page, marked with the app's name, and can switch it off there.

Creating a subscription sends a `ping` event to the address, and **Send a test** (`POST …/webhooks/{webhook}/test`) sends one again at any time.

```sh
curl -X POST "https://<your projqo address>/api/v1/orgs/{org}/webhooks" \
  -H "Authorization: Bearer $PROJQO_TOKEN" -H "Content-Type: application/json" \
  -d '{"url": "https://hooks.example.com/projqo",
       "events": ["task_created", "task_updated"],
       "projects": ["WEB"]}'
```

The body takes `url` (https, no variables), `events`, and optionally `name`, `projects` and `spaces` (keys or ids: only events about their things; Docs events are narrowed by `spaces`, everything in a project by `projects`; events about neither, such as people, aren't narrowed), `task_query` (only task events whose task matches it) and `enabled`. The answer holds the subscription and its `secret`, **shown only this once**. A token or app connection has at most 20 subscriptions, and each is listed, read, changed and deleted only through the token or app that made it.

- A subscription stops when its token is revoked or expires, when its person leaves the organisation or becomes a guest, or when its app's connection ends (it is deleted with the connection, or with a revoked token).
- `enabled: false` switches it off and `enabled: true` on again, except when an organisation admin switched it off: then only they can.

## The events

| Event | When | Group | Needs |
|---|---|---|---|
| `task_created` | Task created | Tasks | `tasks:read` |
| `task_updated` | Task updated | Tasks | `tasks:read` |
| `task_deleted` | Task deleted | Tasks | `tasks:read` |
| `comment_created` | Comment created | Comments | `tasks:read` |
| `comment_updated` | Comment updated | Comments | `tasks:read` |
| `comment_deleted` | Comment deleted | Comments | `tasks:read` |
| `worklog_created` | Work log created | Work logs | `worklogs:read` |
| `worklog_updated` | Work log updated | Work logs | `worklogs:read` |
| `worklog_deleted` | Work log deleted | Work logs | `worklogs:read` |
| `attachment_created` | File attached | Files and links | `tasks:read` |
| `attachment_deleted` | File removed | Files and links | `tasks:read` |
| `link_created` | Link created | Files and links | `tasks:read` |
| `link_deleted` | Link removed | Files and links | `tasks:read` |
| `sprint_created` | Sprint created | Sprints | `boards:read` |
| `sprint_deleted` | Sprint deleted | Sprints | `boards:read` |
| `sprint_updated` | Sprint updated | Sprints | `boards:read` |
| `sprint_started` | Sprint started | Sprints | `boards:read` |
| `sprint_closed` | Sprint closed | Sprints | `boards:read` |
| `board_created` | Board created | Boards | `boards:read` |
| `board_deleted` | Board deleted | Boards | `boards:read` |
| `board_updated` | Board updated | Boards | `boards:read` |
| `board_settings_changed` | Board settings changed | Boards | `boards:read` |
| `version_released` | Release released | Releases | `projects:read` |
| `version_unreleased` | Release unreleased | Releases | `projects:read` |
| `version_created` | Release created | Releases | `projects:read` |
| `version_moved` | Release moved | Releases | `projects:read` |
| `version_updated` | Release updated | Releases | `projects:read` |
| `version_merged` | Release merged | Releases | `projects:read` |
| `version_deleted` | Release deleted | Releases | `projects:read` |
| `project_created` | Project created | Projects | `projects:read` |
| `project_updated` | Project updated | Projects | `projects:read` |
| `project_deleted` | Project deleted | Projects | `projects:read` |
| `project_trashed` | Project moved to the trash | Projects | `projects:read` |
| `project_restored` | Project restored | Projects | `projects:read` |
| `project_archived` | Project archived | Projects | `projects:read` |
| `task_type_created` | Task type created | Task types | `projects:read` |
| `task_type_updated` | Task type updated | Task types | `projects:read` |
| `task_type_deleted` | Task type deleted | Task types | `projects:read` |
| `filter_created` | Filter created | Filters | `filters:read` |
| `filter_updated` | Filter updated | Filters | `filters:read` |
| `filter_deleted` | Filter deleted | Filters | `filters:read` |
| `person_added` | Person added | People | `people:read` |
| `person_removed` | Person removed | People | `people:read` |
| `person_changed` | Person changed | People | `people:read` |
| `option_changed` | An option switched | Options | `org:read` |
| `space_created` | Space created | Spaces | `docs:read` |
| `space_updated` | Space updated | Spaces | `docs:read` |
| `space_deleted` | Space deleted | Spaces | `docs:read` |
| `page_created` | Page created | Pages | `docs:read` |
| `page_published` | Page published | Pages | `docs:read` |
| `page_updated` | Page updated | Pages | `docs:read` |
| `page_moved` | Page moved | Pages | `docs:read` |
| `page_trashed` | Page moved to the trash | Pages | `docs:read` |
| `page_restored` | Page restored | Pages | `docs:read` |
| `page_deleted` | Page deleted | Pages | `docs:read` |
| `page_comment_created` | Page comment created | Page comments | `docs:read` |
| `page_comment_updated` | Page comment updated | Page comments | `docs:read` |
| `page_comment_deleted` | Page comment deleted | Page comments | `docs:read` |

The [webhook events reference](/reference/webhook-events/) shows each event's `data`. For a thing the API can read, `data` is exactly what its `GET` answers (a task, a comment, a release…). For a thing that is gone, such as a deleted comment, or one the API has no call for yet, it is a `WebhookItem`: its id, its kind and what it belongs to. A deleted comment, work log, file or link goes to whoever can still open its task; a deleted task to whoever could open it; a deleted page (by id, without its title) to whoever can open its space; anything else that is gone (a project, release, person, space, sprint, board, task type or filter) only to subscriptions whose person is an owner or admin of the organisation.

`ping` isn't subscribed to: it comes on creating a subscription and with **Send a test**.

## What a delivery looks like

projqo sends a `POST` with a JSON body, the **envelope**:

```json
{
  "id": "…",
  "event": "task_updated",
  "created_at": "2026-12-01T09:30:00Z",
  "api_version": "v1",
  "organisation": { "id": "…", "address": "acme" },
  "actor": { "id": "…", "name": "Zoe Patel" },
  "data": { … }
}
```

- `id` is the delivery's id. A delivery can arrive more than once: use the id to skip one you've already handled.
- `data` is the thing that changed, exactly as `GET` returns it in v1.
- `actor` is the person who made the change, or `null` when projqo made it.
- `api_version` is `v1`. A field may be added within v1; one is never taken away or renamed.

And these headers:

| Header                        | Holds                                                             |
| ----------------------------- | ----------------------------------------------------------------- |
| `X-Projqo-Event`              | The event, such as `task_updated`.                                |
| `X-Projqo-Delivery`           | The delivery's id.                                                |
| `X-Projqo-Timestamp`          | When it was signed, in seconds since 1970 (UTC).                  |
| `X-Projqo-Signature`          | `sha256=` and the signature, in hex.                              |
| `X-Projqo-Signature-Previous` | For 24 hours after a rotation: the signature with the old secret. |

A delivery is prepared as the person whose app or token made the subscription, when it is sent: something that person can't open (any more) is skipped and logged with the reason, never sent. The token or app must still have the event's read scope.

## Checking the signature

Each subscription has its own secret, shown once when it is made. projqo signs every delivery with it: the signature is HMAC-SHA256, keyed with the secret, over the timestamp, a full stop, and the body exactly as sent:

```text
sha256=hex(HMAC_SHA256(secret, "<X-Projqo-Timestamp>.<body>"))
```

Check every delivery before you trust it:

1. Read the body as raw bytes, before any JSON parsing.
2. Refuse a timestamp more than 5 minutes away from your clock, so an old delivery can't be sent again by someone who caught it.
3. Work out the signature yourself and compare it with the sent one in constant time.

:::tabs

```js title="JavaScript"
import { createHmac, timingSafeEqual } from "node:crypto";

const FIVE_MINUTES = 5 * 60;

/** True when the delivery was signed with `secret` in the last five minutes. */
export function checkSignature(rawBody, headers, secret, now = Date.now()) {
  const timestamp = String(headers["x-projqo-timestamp"] ?? "");
  if (!/^\d+$/.test(timestamp) || Math.abs(now / 1000 - Number(timestamp)) > FIVE_MINUTES)
    return false;
  const expected = Buffer.from(
    "sha256=" + createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex"),
  );
  // While a secret is being rotated, a second signature is sent too: either may match.
  const sent = Object.entries(headers)
    .filter(([name]) => name.toLowerCase().startsWith("x-projqo-signature"))
    .flatMap(([, value]) => String(value).split(","))
    .map((s) => Buffer.from(s.trim()));
  return sent.some((s) => s.length === expected.length && timingSafeEqual(s, expected));
}
```

```py title="Python"
import hashlib
import hmac
import time

FIVE_MINUTES = 5 * 60


def check_signature(raw_body: bytes, headers, secret: str, now=None) -> bool:
    """True when the delivery was signed with `secret` in the last five minutes."""
    timestamp = ""
    for name, value in headers.items():
        if name.lower() == "x-projqo-timestamp":
            timestamp = value
    now = time.time() if now is None else now
    if not timestamp.isdigit() or abs(now - int(timestamp)) > FIVE_MINUTES:
        return False
    mac = hmac.new(secret.encode(), timestamp.encode() + b"." + raw_body, hashlib.sha256)
    expected = "sha256=" + mac.hexdigest()
    # While a secret is being rotated, a second signature is sent too: either may match.
    sent = [
        part.strip()
        for name, value in headers.items()
        if name.lower().startswith("x-projqo-signature")
        for part in value.split(",")
    ]
    return any(hmac.compare_digest(s, expected) for s in sent)
```

:::

And a receiver that uses it:

:::tabs

```js title="JavaScript"
import { createServer } from "node:http";
import { checkSignature } from "./check-signature.mjs";

createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) chunks.push(chunk);
  const raw = Buffer.concat(chunks).toString("utf8");
  if (!checkSignature(raw, req.headers, process.env.PROJQO_WEBHOOK_SECRET)) {
    res.writeHead(401).end();
    return;
  }
  const delivery = JSON.parse(raw);
  res.writeHead(204).end(); // answer first, then do the work
  console.log(delivery.event, delivery.id);
}).listen(8080);
```

```py title="Python"
import json
import os

from flask import Flask, request

from check_signature import check_signature

app = Flask(__name__)


@app.post("/projqo")
def receive():
    raw = request.get_data()
    if not check_signature(raw, request.headers, os.environ["PROJQO_WEBHOOK_SECRET"]):
        return "", 401
    delivery = json.loads(raw)
    print(delivery["event"], delivery["id"])
    return "", 204
```

:::

### Rotating the secret

A subscription's secret can be rotated with `POST …/webhooks/{webhook}/rotate-secret`, which answers the new secret (shown only then). For 24 hours after, each delivery is signed with both the new and the old secret, the old one in `X-Projqo-Signature-Previous`, so a receiver still holding the old secret keeps working while you deploy the new one. Rotating again within those 24 hours ends the older secret at once. The examples above accept either signature.

## Answering a delivery

- Answer with any `2xx` status within 10 seconds. Do the work after answering, or in a queue.
- Anything else (another status, no answer in time, a redirect) counts as a failure. projqo doesn't follow redirects.

## Retries

A failed delivery is tried again after 30 seconds, 2 minutes, 8 minutes, 32 minutes and about 2 hours. After that it is marked failed.

A subscription whose deliveries keep failing is **switched off**: after 50 failed deliveries in a row (each after its retries), or after 3 days of nothing but failures. Who is emailed: for an app's subscription, the owners and admins of the organisation that registered the app; for a token's, the token's person. It stays off until it is switched on again by hand (`PATCH` with `enabled: true`), and its count starts again. The subscription's `health` shows the failures in a row, since when it has been failing and its last success; `switched_off.reason` says `failing`.

## The delivery log

Every delivery is kept for 30 days: its status (`queued`, `sent`, `failed` or `skipped`), the attempts, your answer's status code, how long it took, and the reason it failed or was skipped. Read it with `GET …/webhooks/{webhook}/deliveries` (newest first, `status=` to narrow it) or on the Webhooks page in projqo, and **Redeliver** a finished one (`POST …/deliveries/{delivery}/redeliver`) to send it again, with the same id, prepared again as the subscription's person.

## How many a day

Each organisation can receive a number of deliveries a day, by its plan (see [rate limits](/guides/rate-limits/#the-limits-by-plan)), counted per UTC day. Over it, deliveries wait until midnight (UTC), nothing is lost, and the organisation's owners and admins are emailed once that day.
