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

# Subscriptions

> Receive signed HTTPS webhooks in real time whenever your factory replies, a Worker changes state, or work needs human Review.

**Subscriptions** push real-time updates *out* of your factory straight to your backend over signed HTTPS webhooks—so your custom interface stays responsive without polling. (For how external events flow *into* your factory, see [Event routing vs. outbound Subscriptions](https://docs.myworklayer.com/events.md#event-routing-vs-outbound-subscriptions).)

In the support example, subscribing to `room.response` and `reviews.approvals.created` lets your app post factory replies into your help desk the instant they arrive and alert a support lead the moment a refund needs sign-off.

![Signed webhook delivery: factory events are signed with Standard Webhooks HMAC-SHA256, POSTed to your HTTPS endpoint for a 2xx within 10s, or retried with exponential backoff up to 7 attempts.](https://mintcdn.com/worklayer-17401167/cpUXFKQRIMsNdzrq/images/diagrams/subscriptions-delivery-light.svg?fit=max\&auto=format\&n=cpUXFKQRIMsNdzrq\&q=85\&s=75d3878fe7c144e6b1031345ae6f6e5d)

## Event topics

A Subscription delivers every topic you subscribe to across **all Rooms** of the factory.

In topic names, `reviews.*` refers to [Reviews](https://docs.myworklayer.com/review.md) waiting on human input (questions, tool approvals, or app connections).

| Topic | Triggered when |
| - | - |
| [`room.response`](https://docs.myworklayer.com/api-reference/subscription-events/room-response) | The factory posts a user-facing reply in a Room. |
| [`room.status`](https://docs.myworklayer.com/api-reference/subscription-events/room-status) | The factory starts (`running`) or finishes (`idle`) working in a Room. |
| [`worker.status`](https://docs.myworklayer.com/api-reference/subscription-events/worker-status) | A [Worker](https://docs.myworklayer.com/workers.md) transitions status. |
| [`reviews.questions.created`](https://docs.myworklayer.com/api-reference/subscription-events/question-created) | A Worker pauses to ask one or more questions. |
| [`reviews.approvals.created`](https://docs.myworklayer.com/api-reference/subscription-events/approval-created) | A Worker pauses for tool-call approval. |
| [`reviews.connect_apps.created`](https://docs.myworklayer.com/api-reference/subscription-events/connect-app-created) | A Worker pauses because an app needs to be connected. |
| [`webhook.test`](https://docs.myworklayer.com/api-reference/subscription-events/test-event) | You send a manual test event from the web app. |

Events submitted with `delivery: "context"` never trigger webhooks, and a `steer` Event arriving while a Room is already working does not emit a duplicate `room.status` transition. See [Which webhooks an Event causes](https://docs.myworklayer.com/events.md#which-webhooks-an-event-causes).

## Create a Subscription

Create and manage Subscriptions either through the Factory API or in the Worklayer web app—both manage the same underlying resource.

> [tab] API
>
> ```bash theme={null}
> curl -X POST "https://api.myworklayer.com/v1/subscriptions"       -H "Authorization: Bearer $WORKLAYER_API_KEY"       -H "Content-Type: application/json"       -d '{
>     "name": "Support backend",
>     "url": "https://hooks.example.com/worklayer",
>     "events": ["room.response", "reviews.approvals.created"]
>   }'
> ```
>
> Save the `secret` returned in the `201 Created` response immediately—Worklayer displays it only once. See the [Subscriptions API reference](https://docs.myworklayer.com/api-reference/subscriptions/create-a-subscription.md) for list, update, delete, and rotation routes.

> [tab] Web app
>
> 1. Open your factory in the Worklayer web app and go to **Develop**.
> 2. Under **Webhooks**, select **Add webhook**.
> 3. Enter your HTTPS endpoint URL and select the event topics.
> 4. Copy and store the signing secret immediately—it is shown only once.

### Endpoint URL requirements

Your destination URL must be a publicly reachable `https://` URL up to **2,048 characters** long:

* No embedded username, password, or `#fragment`.
* Cannot target `localhost`, `*.localhost`, or private/reserved IP ranges (including hostnames that resolve to private or reserved IPs).

Enabling/disabling a Subscription, firing `webhook.test` events, and inspecting delivery attempt logs are available in the Worklayer web app.

## Webhook payload

Every delivery uses a consistent envelope:

```json theme={null}
{
  "id": "0d6a3f9e-2c41-4b8e-a7d5-91f3c0e6b2a4",
  "type": "room.response",
  "environmentId": "cmh2v8x0q0000l708kq3w9f6t",
  "occurredAt": "2026-11-20T16:04:12.528Z",
  "data": {
    "roomId": "cmhx3q7v20004l808sd5k2r1m",
    "messageId": "toolu_01HbW7q2Lk9sVd3XnR8cPz4m",
    "text": "I refunded the duplicate charge for order 1188 and notified Dana Lee."
  }
}
```

* `id` — unique event identifier.
* `environmentId` — the ID of your [factory](https://docs.myworklayer.com/factory.md).
* `data` — topic-specific payload (linked from each topic in the table above).

## Signing

Worklayer signs every webhook using the [Standard Webhooks](https://www.standardwebhooks.com/) specification and includes three headers:

| Header | Description |
| - | - |
| `webhook-id` | Unique delivery ID, identical across all retry attempts of the same delivery. |
| `webhook-timestamp` | Attempt timestamp in Unix seconds. |
| `webhook-signature` | One or more space-separated signatures formatted as `v1,<base64>`. |

Always verify the signature against the **raw request body** before parsing or acting on the payload:

```javascript Node.js theme={null}
import { createHmac, timingSafeEqual } from 'node:crypto';

export function verifyWorklayerWebhook(rawBody, headers, secret) {
  const id = headers['webhook-id'];
  const timestamp = headers['webhook-timestamp'];
  const signatures = headers['webhook-signature'];
  if (!id || !timestamp || !signatures) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;

  const key = Buffer.from(secret.slice('whsec_'.length), 'base64');
  const expected = createHmac('sha256', key)
    .update(`${id}.${timestamp}.`)
    .update(rawBody)
    .digest();

  return signatures.split(' ').some((entry) => {
    const [version, value] = entry.split(',');
    if (version !== 'v1' || !value) return false;
    const given = Buffer.from(value, 'base64');
    return given.length === expected.length && timingSafeEqual(given, expected);
  });
}
```

How verification works:

1. Strip the `whsec_` prefix from your secret and base64-decode the remainder to get the raw HMAC key.
2. Construct the signed string: `{webhook-id}.{webhook-timestamp}.{rawBody}`.
3. Compute the base64-encoded HMAC-SHA256 digest.
4. Compare in constant time against every `v1,` entry in `webhook-signature`. Accept the request if any signature matches.

Never parse and re-serialize the JSON before verifying—whitespace or key-order changes will invalidate the signature. Rejecting timestamps older than 5 minutes (300 seconds) is recommended to guard against replay attacks.

### Rotate the secret

Rotate a Subscription's signing secret via [Rotate the signing secret](https://docs.myworklayer.com/api-reference/subscriptions/rotate-the-signing-secret.md) or the web app. The new secret is returned only once in that response.

For **24 hours** after rotation, Worklayer dual-signs every delivery with both the new secret and the immediately preceding secret (`webhook-signature` contains both space-separated signatures). Your handler should accept a webhook if *any* signature matches. Only one previous secret stays active—rotating a second time within 24 hours invalidates the oldest secret immediately.

## Retries

Respond with any `2xx` status within **10 seconds** to acknowledge delivery. Offload heavy processing to a background queue after responding.

Worklayer retries automatically on timeouts (> 10s), network errors, and `408`, `425`, `429`, or `5xx` responses using exponential backoff:

| After attempt | Backoff delay |
| - | - |
| 1 | 1 minute |
| 2 | 5 minutes |
| 3 | 30 minutes |
| 4 | 2 hours |
| 5 | 6 hours |
| 6 | 15 hours |

If attempt 7 fails, delivery stops permanently. Other non-`2xx` responses (such as `400` or `3xx` redirects) fail immediately without retrying. Updating a Subscription's URL, disabling it, or deleting it cancels any pending retries. Worklayer retains webhook event logs for **30 days**.

## Deduplication and ordering

* **At-least-once delivery:** retries can occasionally deliver the same event twice. Deduplicate using `webhook-id`.
* **Out-of-order arrivals:** `room.status` and `worker.status` payloads include `actorRevision` and `revision`. To ensure stale updates never overwrite newer state, compare `actorRevision` first (higher is newer), then `revision` when `actorRevision` values match.

> [card] [Subscription API reference](https://docs.myworklayer.com/api-reference/subscriptions/list-subscriptions.md)
>
> Create, update, rotate, and delete Subscriptions via HTTP.

> [card] [Review](https://docs.myworklayer.com/review.md)
>
> Handle approval, question, and connect-app webhooks end to end.


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