> ## 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.

# Create your first factory

> Go from a blank Worklayer factory to a custom interface wired to the Factory API—using a UI-first prompt in your coding agent or step-by-step cURL calls.

The fastest way to build on the Factory API is **UI-first with your coding agent**:

1. **Configure your factory in the web app** — connect the [apps](https://docs.myworklayer.com/apps.md) your factory needs, set approval policies, and generate an API key.
2. **Design and mock the interface first** — describe the experience you want (not Rooms or plumbing) and have your coding agent build the UI against static mock data.
3. **Wire it to the Factory API** — hand these docs to your coding agent to connect Rooms, Events, Worker streams, Reviews, and signed Subscriptions.

## Set up your factory and API key

Factory setup—creating the factory, connecting apps, setting tool policies, and issuing API keys—happens in the Worklayer web app. You must be the factory's owner to generate an API key.

**1. Connect apps and tool policies**

In the Worklayer web app, create or open your factory and connect the [apps](https://docs.myworklayer.com/apps.md) your workflow needs (for example, GitHub, Sentry, PostHog, and Cursor Cloud Agents for an issue-resolution factory—or Stripe and Slack for a support factory).

Set read-only tools to **Allow** and sensitive actions (such as merging PRs, issuing refunds, or messaging customers) to **Ask** so they surface as [Reviews](https://docs.myworklayer.com/review.md) in your interface.

**2. Generate a factory API key**

Go to **Develop** → **API**, select **New key**, give it a name, and select **Create key**.

Copy the key right away—Worklayer shows it only once. See [Authentication](https://docs.myworklayer.com/authentication.md) for security and scoping details.

```bash theme={null}
export WORKLAYER_API_KEY="wrk-..."
```

## Build your integration

Choose **Prompt your coding agent** to build a custom UI or backend with Claude Code, Cursor, or Codex, or switch to **Manual walkthrough** to explore each endpoint directly with cURL.

> [tab] Prompt your coding agent
>
> Copy one of the prompts below into Claude Code, Cursor, or Codex. Both follow the Factory API architecture: keep `WORKLAYER_API_KEY` server-side only, isolate one Room per work item, handle Reviews inline, and verify signed webhooks.
>
> ### Option A: Build a custom UI (Auto Issue Resolve dashboard)
>
> ```text theme={null}
> Build a Next.js (TypeScript) custom interface for an "Auto Issue Resolve" factory using the Worklayer Factory API.
>
> Workflow:
> 1. Build the UI first with realistic static mock data so I can review the interface before wiring live API calls.
> 2. Then wire all API calls through server-side Route Handlers / Server Actions so WORKLAYER_API_KEY is never exposed to the browser.
>
> Interface requirements (use a live dashboard and issue list, not a Kanban board):
> - Top system overview: issues fixed over time, incoming issue volume trend, and active Worker count.
> - Issue list: search and filter issues by user impact and a composite criticality score, with one primary action button per issue: "Fix with Agent".
> - Live detail drawer/page for an issue: stream Worker progress in real time, allow quick steering replies to unblock the Worker, and render inline Review cards (approvals, questions, connect-app links).
> - Completion report: fix status, high-level summary, PR link(s), CI status, merge risk level (auto-merge / 1 approval / 2 approvals), and a post-merge rollback action that triggers a revert Event.
>
> Worklayer Factory API contract:
> - Base URL: https://api.myworklayer.com/v1
> - Auth: Authorization: Bearer $WORKLAYER_API_KEY (server-side only)
> - Rooms: POST /v1/rooms with { name, externalKey: `issue-${issueId}` } (on 409 Conflict, reuse roomId from the response body).
> - Events: POST /v1/rooms/{roomId}/events with Idempotency-Key and { type, content, modelContext, attributes, delivery: "queue" | "steer" | "context" }. Use "queue" for "Fix with Agent" and "steer" for mid-flight corrections.
> - Workers: GET /v1/rooms/{roomId}/workers, GET /v1/rooms/{roomId}/workers/{workerId}/messages, POST /v1/rooms/{roomId}/workers/{workerId}/messages ({ text, delivery: "queue" | "steer" }), and proxy GET /v1/rooms/{roomId}/workers/{workerId}/stream (SSE) through a server route.
> - Reviews: GET /v1/rooms/{roomId}/reviews, POST /v1/rooms/{roomId}/reviews/{requestId}/decision ({ decision: "approve" | "deny" }), POST /v1/rooms/{roomId}/reviews/{requestId}/answer, GET /v1/rooms/{roomId}/reviews/{requestId}/connect-app.
> - Subscriptions: POST /v1/subscriptions for ["room.response", "room.status", "worker.status", "reviews.approvals.created", "reviews.questions.created", "reviews.connect_apps.created"] and verify Standard Webhooks HMAC-SHA256 signatures (webhook-id, webhook-timestamp, webhook-signature) against the raw request body using the whsec_ secret.
> ```
>
> ### Option B: Build a backend integration (Support ticket flow)
>
> ```text theme={null}
> Build a small Node.js (TypeScript) backend integration for my Worklayer factory using the Worklayer Factory API.
>
> Base URL: https://api.myworklayer.com/v1
> Auth header: Authorization: Bearer $WORKLAYER_API_KEY (read from process.env.WORKLAYER_API_KEY)
>
> Implement a working support-ticket flow with:
> 1. Room management: POST /v1/rooms with { name, externalKey } for a ticket. If it returns 409 Conflict, reuse the roomId from the response body.
> 2. Event ingestion: POST /v1/rooms/{roomId}/events with an Idempotency-Key header, { type: "ticket.created", content, attributes, delivery: "queue" }. Also add a helper to send follow-up corrections with delivery: "steer".
> 3. Room History: GET /v1/rooms/{roomId}/history to read event and response entries.
> 4. Review handling: GET /v1/rooms/{roomId}/reviews to list pending approvals, questions, or connect_app requests, and POST /v1/rooms/{roomId}/reviews/{requestId}/decision with { decision: "approve" | "deny" }.
> 5. Subscriptions: a helper to register a webhook via POST /v1/subscriptions for ["room.response", "reviews.approvals.created", "reviews.questions.created"], plus an HTTP webhook handler that verifies Standard Webhooks HMAC-SHA256 signatures (webhook-id, webhook-timestamp, webhook-signature) using the raw request body and whsec_ signing secret.
>
> Include a runnable smoke-test script that creates a Room for a sample duplicate-charge ticket, sends the Event, polls Room History and pending Reviews, and prints the factory's response.
> ```
>
> > [!TIP]
> >
> > Want your coding agent to also inspect your Worklayer apps, skills, memory, and files directly while building? Connect the [Worklayer MCP](https://docs.myworklayer.com/mcp/connect.md) in one step.

> [tab] Manual walkthrough
>
> **1. Create a Room**
>
> A [Room](https://docs.myworklayer.com/rooms.md) isolates one conversation with your factory. Create one Room per support ticket using your own `externalKey` so you can look it up reliably on future updates:
>
> ```bash theme={null}
> curl -X POST "https://api.myworklayer.com/v1/rooms"           -H "Authorization: Bearer $WORKLAYER_API_KEY"           -H "Content-Type: application/json"           -d '{"name": "Ticket 4821", "externalKey": "zendesk-ticket-4821"}'
> ```
>
> ```json theme={null}
> {
>   "id": "cmhx3q7v20004l808sd5k2r1m",
>   "source": "api",
>   "kind": "api",
>   "name": "Ticket 4821",
>   "externalKey": "zendesk-ticket-4821",
>   "lastActivityAt": null,
>   "createdAt": "2026-11-19T17:40:55.204Z"
> }
> ```
>
> Save the returned Room ID:
>
> ```bash theme={null}
> export ROOM_ID="cmhx3q7v20004l808sd5k2r1m"
> ```
>
> > [!NOTE]
> >
> > To interact with the factory's main web conversation instead of creating a new Room, pass `web` as `roomId` and skip this step. See [The main Room](https://docs.myworklayer.com/rooms.md#the-main-room).
>
> **2. Send an Event**
>
> Tell your factory what happened. Include an `Idempotency-Key` so network retries never create duplicate Events:
>
> ```bash theme={null}
> curl -X POST "https://api.myworklayer.com/v1/rooms/$ROOM_ID/events"           -H "Authorization: Bearer $WORKLAYER_API_KEY"           -H "Content-Type: application/json"           -H "Idempotency-Key: zendesk-ticket-4821-created"           -d '{
>     "type": "ticket.created",
>     "content": "Ticket 4821 from Dana Lee: I was charged twice for order 1188. Please refund one charge."
>   }'
> ```
>
> ```json theme={null}
> { "eventId": "b7e4c1d2-8a3f-4f6e-9d20-5c1a7e9b3f08", "delivery": "queue" }
> ```
>
> `202 Accepted` confirms Worklayer persisted the Event and queued it for your factory to handle. See [Events](https://docs.myworklayer.com/events.md).
>
> **3. Read the Room History**
>
> Fetch the conversation to see what your factory replied:
>
> ```bash theme={null}
> curl "https://api.myworklayer.com/v1/rooms/$ROOM_ID/history"           -H "Authorization: Bearer $WORKLAYER_API_KEY"
> ```
>
> ```json theme={null}
> {
>   "messages": [
>     {
>       "id": "cmhx3r0a10007l808m2c4t9xw",
>       "kind": "event",
>       "text": "Ticket 4821 from Dana Lee: I was charged twice for order 1188. Please refund one charge.",
>       "createdAt": "2026-11-19T17:41:02.118Z",
>       "eventId": "b7e4c1d2-8a3f-4f6e-9d20-5c1a7e9b3f08"
>     },
>     {
>       "id": "toolu_01HbW7q2Lk9sVd3XnR8cPz4m",
>       "kind": "response",
>       "text": "I'm checking order 1188. A support lead needs to approve the refund before I process it.",
>       "createdAt": "2026-11-19T17:41:40.512Z"
>     }
>   ],
>   "nextCursor": null
> }
> ```
>
> Entries with `kind: "response"` are the factory's user-facing replies. See [Room History](https://docs.myworklayer.com/rooms.md#room-history).
>
> **4. Resolve a Review**
>
> To issue the refund, the factory starts a [Worker](https://docs.myworklayer.com/workers.md). Because refunding a charge requires human sign-off, the Worker pauses and opens a [Review](https://docs.myworklayer.com/review.md). List pending Reviews for the Room:
>
> ```bash theme={null}
> curl "https://api.myworklayer.com/v1/rooms/$ROOM_ID/reviews"           -H "Authorization: Bearer $WORKLAYER_API_KEY"
> ```
>
> ```json theme={null}
> {
>   "requests": [
>     {
>       "requestId": "wr1.Y2x4Mmh0cTlrMDAwMQ.2.Qm9vVGF0Y2hlcy1maW5nZXJwcmludC1leGFtcGxlXzQz",
>       "workerId": "6f1c2a9e-4b7d-4e2a-9c51-3d8e0b7a1f24",
>       "kind": "approval",
>       "calls": [
>         { "tool": "stripe_create_refund", "callNumber": 1, "inputFields": ["charge", "amount"] }
>       ]
>     }
>   ]
> }
> ```
>
> Approve the request using its `requestId`:
>
> ```bash theme={null}
> curl -X POST "https://api.myworklayer.com/v1/rooms/$ROOM_ID/reviews/$REQUEST_ID/decision"           -H "Authorization: Bearer $WORKLAYER_API_KEY"           -H "Content-Type: application/json"           -d '{"decision": "approve"}'
> ```
>
> The Worker immediately resumes and completes the refund. When no work is waiting for human input, `requests` is empty. (Tool names reflect whichever apps you connected to your factory.)
>
> **5. Subscribe to real-time updates**
>
> Instead of polling Room History and Reviews, register a [Subscription](https://docs.myworklayer.com/subscriptions.md) so Worklayer pushes signed webhooks directly to your backend:
>
> ```bash theme={null}
> curl -X POST "https://api.myworklayer.com/v1/subscriptions"           -H "Authorization: Bearer $WORKLAYER_API_KEY"           -H "Content-Type: application/json"           -d '{
>     "url": "https://hooks.example.com/worklayer",
>     "events": ["room.response", "reviews.approvals.created"]
>   }'
> ```
>
> The `201 Created` response includes a signing `secret` (`whsec_...`). Save it immediately—the API returns it only once.
>
> When the factory finishes and replies, your endpoint receives:
>
> ```json theme={null}
> {
>   "id": "0d6a3f9e-2c41-4b8e-a7d5-91f3c0e6b2a4",
>   "type": "room.response",
>   "environmentId": "cmh2v8x0q0000l708kq3w9f6t",
>   "occurredAt": "2026-11-19T17:52:08.311Z",
>   "data": {
>     "roomId": "cmhx3q7v20004l808sd5k2r1m",
>     "messageId": "toolu_01HbW7q2Lk9sVd3XnR8cPz4m",
>     "text": "I refunded the duplicate charge for order 1188 and notified Dana Lee."
>   }
> }
> ```
>
> See [Subscriptions](https://docs.myworklayer.com/subscriptions.md#signing) to verify webhook signatures before processing payloads.

## Next steps

> [card] [Connect apps & tool policies](https://docs.myworklayer.com/apps.md)
>
> See supported built-in apps, custom remote MCP servers, OpenAPI specs, and approval rules.

> [card] [What Workers can and cannot do](https://docs.myworklayer.com/workers.md#what-workers-can-and-cannot-do)
>
> Understand sandboxed scripts, connected coding agents, files, and execution boundaries.


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