> ## Documentation Index
> Fetch the complete documentation index at: https://developers.circularo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# React to events with webhooks

Polling tells you what changed only as often as you ask. A webhook has Circularo call you instead, the moment a document event happens in your organization. Registering one takes a single call; securing the deliveries, and receiving them safely, is the rest of this guide.

## Before you begin

* **An organization-administrator key.** A webhook belongs to the whole organization, so a key issued to a regular member is refused with `403` — and so is an administrator's key when webhooks are not enabled for the organization.
* **An HTTPS endpoint that accepts POST requests.** A webhook registered through the API delivers to `https` URLs only; an `http` callback is rejected with `400`.

## What a delivery looks like

Circularo sends a JSON `POST` to your callback URL with four fields, and nothing else:

| Field | What it holds |
| - | - |
| `documentId` | The document the event happened to |
| `event` | What happened, as a name like `documentCreated`, `signRequest`, `documentSigned` or `documentCompleted` |
| `actor` | Who caused it, or `null` when Circularo raised the event itself — such as `signExpired` |
| `timestamp` | When it happened |

The notification carries no document content — it is a pointer. Read the document itself when you need more than the fact that something changed.

Branch on the events you care about and ignore the rest: further event names exist and more can appear, so a receiver that treats an unrecognized `event` as a no-op keeps working.

## Step 1: Register the webhook

Give Circularo the URL, and choose how the deliveries should be secured:

```http Request theme={null}
POST /webhooks
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

{
  "callbackUrl": "https://example.com/webhooks/circularo",
  "hmacSecret": "s3cr3t-signing-key"
}
```

* `hmacSecret` signs each payload: the delivery carries the HMAC-SHA256 of the raw body in an `X-Circularo-Signature` header, which also proves nothing altered it in transit.
* `basicAuth` takes a `username` and a `password` and puts an ordinary `Authorization: Basic` header on each delivery — usually the easier one to put in front of an existing endpoint.
* A webhook uses one of the two, never both; sending both is rejected with `400`.
* Credentials do not belong in the callback URL — `https://user:password@example.com/webhooks` is rejected with `400`.

```http Response theme={null}
HTTP/2 201

{
  "basicAuth": null,
  "callbackUrl": "https://example.com/webhooks/circularo",
  "createdAt": "2026-05-11T09:30:00.000Z",
  "createdBy": {
    "email": "john.smith@example.com",
    "fullname": "John Smith",
    "userId": "john.smith@example.com"
  },
  "id": "Zq4tXm7RkP2nWv5bLdCy",
  "isHmacConfigured": true
}
```

`isHmacConfigured` confirms the secret was stored. The secret itself is write-only — it is never returned again, here or anywhere else. The same holds for a `basicAuth` password: the response reports the user name and nothing else.

Keep the `id`; it is what you update and delete the webhook by.

## Step 2: See the webhooks you have

The organization's webhooks come back as an ordinary paged collection:

```http Request theme={null}
GET /webhooks
Authorization: Bearer YOUR_API_KEY
```

```http Response theme={null}
HTTP/2 200

{
  "pagination": {
    "limit": 20,
    "nextCursor": null,
    "offset": 0
  },
  "results": [
    {
      "basicAuth": null,
      "callbackUrl": "https://example.com/webhooks/circularo",
      "createdAt": "2026-05-11T09:30:00.000Z",
      "createdBy": {
        "email": "john.smith@example.com",
        "fullname": "John Smith",
        "userId": "john.smith@example.com"
      },
      "id": "Zq4tXm7RkP2nWv5bLdCy",
      "isHmacConfigured": true
    }
  ],
  "total": 1
}
```

Use this to reconcile what your integration believes it registered with what Circularo will actually call — and to find the `id` of a webhook somebody registered before you.

## Step 3: Change how the webhook is secured

Send only what changes. Here the webhook stops being signed and starts authenticating with HTTP Basic instead:

```http Request theme={null}
PATCH /webhooks/Zq4tXm7RkP2nWv5bLdCy
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

{
  "hmacSecret": null,
  "basicAuth": {
    "username": "circularo-hook",
    "password": "s3cr3t-p4ssw0rd"
  }
}
```

* Omit a field to leave it as it is, send it to replace it, or send `null` to remove it.
* Omitting `basicAuth.password` keeps the stored one, so you can send back the object you just read; include `password` to rotate it.
* Clearing one scheme and setting the other happens in a single request, because a webhook never has both.
* A stored password is never carried to a different endpoint, so a request that changes `callbackUrl` re-sends `basicAuth` in full or drops it.

```http Response theme={null}
HTTP/2 200

{
  "basicAuth": {
    "username": "circularo-hook"
  },
  "callbackUrl": "https://example.com/webhooks/circularo",
  "createdAt": "2026-05-11T09:30:00.000Z",
  "createdBy": {
    "email": "john.smith@example.com",
    "fullname": "John Smith",
    "userId": "john.smith@example.com"
  },
  "id": "Zq4tXm7RkP2nWv5bLdCy",
  "isHmacConfigured": false
}
```

A webhook delivers every document event in the organization — there is no narrower scope to configure, so an update is about where deliveries go and how they authenticate.

## Step 4: Remove the webhook

Deleting a webhook stops the deliveries:

```http Request theme={null}
DELETE /webhooks/Zq4tXm7RkP2nWv5bLdCy
Authorization: Bearer YOUR_API_KEY
```

```http Response theme={null}
HTTP/2 204
```

## Complete example

Two things decide whether a webhook integration is trustworthy, and the receiver below does both.

It verifies the signature, because a callback URL is reachable by anyone and a request arriving there proves nothing on its own. When a secret is configured, every delivery carries an `X-Circularo-Signature` header holding the HMAC-SHA256 of the raw request body, hex-encoded. Compute the same HMAC over the bytes you received — before parsing them, since re-serializing JSON changes them — and compare the two with a timing-safe comparison.

And it answers immediately, before doing any work of its own. A delivery is attempted once and is not repeated: a receiver that fails, or is too slow to answer, loses that notification.

> [!NOTE]
>
> With neither `hmacSecret` nor `basicAuth` the deliveries are unauthenticated, and your endpoint cannot tell a genuine notification from a forged one. Configure one of them whenever the webhook triggers anything that matters.

```js theme={null}
import crypto from "node:crypto";
import http from "node:http";

// the hmacSecret the webhook was registered with
const SECRET = "s3cr3t-signing-key";

const verify = (raw, signature) => {
  const expected = crypto.createHmac("sha256", SECRET).update(raw).digest("hex");
  const received = Buffer.from(signature ?? "", "hex");
  // timing-safe comparison, and equal length is required for it
  return (received.length === expected.length / 2) && crypto.timingSafeEqual(Buffer.from(expected, "hex"), received);
};

http.createServer((req, res) => {
  const chunks = [];
  req.on("data", (chunk) => chunks.push(chunk));
  req.on("end", () => {
    const raw = Buffer.concat(chunks);
    if (!verify(raw, req.headers["x-circularo-signature"])) {
      res.writeHead(401).end();
      return;
    }

    const event = JSON.parse(raw.toString());
    // acknowledge first, process afterwards - the delivery is never repeated
    res.writeHead(204).end();

    if (event.event === "documentCompleted") {
      queue.push(event.documentId); // your own queue, worker, outbox...
    }
  });
}).listen(8080);
```

## Next steps

* Watch a transaction move through its rounds, which is what most events report — [Manage a running transaction](https://developers.circularo.com/guides/signing/manage-transaction.md).
* Read the document a notification points at — [Create a document from a file](https://developers.circularo.com/guides/documents-and-files/create-documents.md).
* The webhook endpoints and their statuses are documented in the API reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.