An AI-built storefront is a Next.js project. Its source lives in the store's design workspace, the same workspace the admin **Design** page and Elliot work in. These endpoints give an outside agent the same access: open the workspace, read and change files, check the code, look at the preview and publish.

Every change lands in the workspace and shows in the preview. Shoppers see nothing until you [publish](#publish-the-storefront).

A store without an AI-built storefront answers `400` on every endpoint here. So does a path outside the project or a file that is off-limits (secrets, git internals, generated output). The `error` message says which.

## Who can call these endpoints

| Caller | Access |
|--------|--------|
| Store API key | Needs the `store:admin` scope. |
| OAuth connection | The team member who connected needs the **Design** permission. |

[Run a command](#run-a-command) is the one exception: it takes the store API key only, and an OAuth connection gets `403`.

## Open the workspace

```
POST /api/v1/storefront/workspace
```

Wakes the design workspace and its live preview, and lists the project's top-level files and folders. Call it once before you read or change files.

```bash
curl -X POST \
  -H "Authorization: Bearer sk_your_api_key" \
  https://your-store.yns.store/api/v1/storefront/workspace
```

### Response (200)

```json
{
  "previewUrl": "https://sb-abc123.vercel.run",
  "topLevel": ["AGENTS.md", "package.json", "public", "src", "tsconfig.json"]
}
```

---

## Get the storefront status

```
GET /api/v1/storefront/workspace
```

Says whether what the preview shows is live, and what changed since the last save.

### Response (200)

| Field | Description |
|-------|-------------|
| `workspaceReadable` | `false` when the workspace could not be read. `unsavedChanges` and `changedFiles` are then unknown, not clean. |
| `workspace` | `read`, `stopped` (the workspace is asleep, so nothing in it is unsaved) or `unreachable` |
| `unsavedChanges`, `changedFiles` | Edits made since the last save. The preview shows them; the live site cannot have them. |
| `managedEdits` | The part of `changedFiles` that is platform-managed. The next publish discards those edits. |
| `setAsideEdits` | Edits set aside because the code changed outside the Design page. They are neither in the preview nor live. |
| `lastPublishLive` | The last publish landed and the public address serves it. Edits made since are in `changedFiles`. |
| `published` | `false` when the store is switched off and its public addresses show the "Coming soon" page |
| `liveUrl` | The store's public address |
| `serving` | `{ state, code?, reason? }`, with `state` `serving`, `not_serving` or `unknown`. Whether the public address answers at all: `not_serving` (a paused store, for example) overrides every other field |
| `live` | `{ sha, deployedAt }` of what the live site serves, or `null` when it can't be determined |
| `draftSha` | The commit the workspace is at |
| `building` | `{ readyState, commitSha, startedAt }` while a publish is still building, otherwise `null` |
| `lastPublish` | How the last publish ended, with its `reason` when it failed |

---

## Read a file

```
GET /api/v1/storefront/files?path=src/app/(store)/page.tsx
```

| Parameter | Type | Description |
|-----------|------|-------------|
| `path` | `string` | File path relative to the project root. Required. |

### Response (200)

```json
{
  "path": "src/app/(store)/page.tsx",
  "content": "export default function Home() { … }",
  "version": "9f2c…e41a",
  "truncated": false
}
```

`version` is a hash of the whole file. Send it as `baseVersion` when you change the file, so a change someone made in between is not overwritten. Content past 200 KB is cut, and `truncated` is `true`.

Answers `404` when the file does not exist.

---

## Write a file

```
PUT /api/v1/storefront/files
```

Creates a file, or replaces its whole content. The preview reloads with it.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `path` | `string` | Yes | File path relative to the project root |
| `content` | `string` | Yes | The whole new content, up to 1,000,000 characters |
| `baseVersion` | `string` | No | The `version` you read the file at. The write is refused with `409` when the file changed since. Leave it out to write regardless |

```json
{ "path": "src/components/banner.tsx", "version": "51ab…07c3" }
```

| Status | Description |
|--------|-------------|
| `409` | The file changed since `baseVersion`, or no longer exists. Read it again |

---

## Edit a file

```
PATCH /api/v1/storefront/files
```

Replaces one piece of text in a file.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `path` | `string` | Yes | File path relative to the project root |
| `oldText` | `string` | Yes | Exact text to replace. It must occur in the file exactly once, so quote enough around the spot to make it unique |
| `newText` | `string` | Yes | What to put in its place |
| `baseVersion` | `string` | No | The `version` you read the file at |

```bash
curl -X PATCH \
  -H "Authorization: Bearer sk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"path":"src/components/hero.tsx","oldText":"Summer sale","newText":"Autumn sale, 20% off","baseVersion":"9f2c…e41a"}' \
  https://your-store.yns.store/api/v1/storefront/files
```

The response is the file's new `{ path, version }`.

| Status | Description |
|--------|-------------|
| `400` | `oldText` does not occur in the file exactly once. Nothing changed |
| `404` | No such file |
| `409` | The file changed since `baseVersion`, or while the edit was made. Read it again |

---

## Run a command

```
POST /api/v1/storefront/commands
```

Runs one bash command in the project root, such as `grep -rn Hero src` or `bun add clsx`, and returns its output and exit code. Each stream returns its last 30,000 characters. The command is stopped after 240 seconds. Use [a check](#start-a-check) for a type check or a build.

Only the store API key can run commands. An OAuth connection gets `403`.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `command` | `string` | Yes | The bash command, up to 4,000 characters |

```json
{ "stdout": "src/components/hero.tsx:12: <h1>Summer sale</h1>\n", "stderr": "", "exitCode": 0 }
```

| Status | Description |
|--------|-------------|
| `400` | The command touches secrets |
| `403` | Called over OAuth instead of with the store API key |

---

## Start a check

```
POST /api/v1/storefront/checks
```

Starts a type check, a lint or a production build in the background and answers `202` with its `id` at once. A check is stopped after 8 minutes.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `check` | `"typecheck" \| "lint" \| "build"` | Yes | `typecheck` runs `bun tsc --noEmit`, `lint` runs `biome check` without changing files, `build` runs `bun run build`, which is what a publish runs |

```json
{ "id": "019642c4-699d-729a-b606-0000000000c1", "command": "bun tsc --noEmit" }
```

## Get a check

```
GET /api/v1/storefront/checks/:id
```

Poll every few seconds until `state` is no longer `running`.

| `state` | Meaning |
|---------|---------|
| `running` | Still running |
| `finished` | Done. `exitCode` 0 means it passed. The errors are at the end of `output`. `124` means it was stopped after 8 minutes |
| `lost` | The workspace restarted and the result is gone. Start the check again |

---

## Screenshot a page

```
POST /api/v1/storefront/screenshots
```

Renders a page of the preview in a headless browser and returns the top of the page as a PNG image. The preview includes unpublished work; the live site is not involved. A screenshot takes a while, so take one per question.

| Field | Type | Description |
|-------|------|-------------|
| `path` | `string` | A page of the store, such as `/` or `/product/ocean-bloom`. Defaults to the homepage |
| `device` | `string` | `desktop`, `ipad-mini`, `iphone-se`, `iphone-17`, `iphone-17-pro-max` or `pixel-7`. Leave it out for a 1280px-wide desktop window |

The response body is `image/png`. These headers describe it:

| Header | Description |
|--------|-------------|
| `X-Screenshot-Path` | The page |
| `X-Screenshot-Viewport` | The browser window, `WxH` |
| `X-Screenshot-Size` | The image, `WxH`. Smaller than the window when it had to shrink |
| `X-Screenshot-Device` | The device, when you asked for one |

Over MCP the image comes back as image content, so the agent sees the page.

## Preview a page

```
POST /api/v1/storefront/preview
```

Wakes the preview and answers its address. Open `previewUrl` + `path` to see the page as the Design page shows it.

| Field | Type | Description |
|-------|------|-------------|
| `path` | `string` | A page of the store. Defaults to the homepage |

```json
{ "previewUrl": "https://sb-abc123.vercel.run", "path": "/product/ocean-bloom" }
```

---

## Find catalog data in the code

```
GET /api/v1/storefront/catalog-findings
```

Scans the source for catalog text written into the code instead of read from the Store API, such as product descriptions or names next to prices. Edits in the admin never reach such text, so change each finding to read from the API.

```json
{
  "findings": [
    {
      "kind": "description",
      "path": "src/app/(store)/page.tsx",
      "line": 42,
      "endLine": 44,
      "entry": { "kind": "product", "id": "019…", "name": "Ocean Bloom", "slug": "ocean-bloom" },
      "excerpt": "Hand-poured soy candle with sea salt…"
    }
  ],
  "note": "…",
  "filesScanned": 86,
  "catalogEntries": 24
}
```

`kind` is `description`, `product-card` or `name`. `entry` is the product or collection the text belongs to. `note` is a summary to act on, `null` when nothing was found.

---

## Page drafts

While the merchant is in the draft view of the Design page, each page has a static HTML draft with the store's Tailwind classes. The merchant sees draft edits at once. They reach the storefront only after the matching change is made in the code.

A draft that does not exist, or edits that do not apply, answer `200` with `{ "ok": false, "error": "…" }` and change nothing.

### Search the drafts

```
GET /api/v1/storefront/drafts?query=Summer%20sale
```

| Parameter | Type | Description |
|-----------|------|-------------|
| `query` | `string` | Exact text or markup to find. Case is ignored. Required |
| `path` | `string` | Search this page only. Leave it out to search every drafted page |

Returns `{ ok: true, pages: [{ path, totalChars, matches }] }`. Each match carries the markup around it, ready to quote in an edit.

### Read a draft

```
GET /api/v1/storefront/drafts/page?path=/&offset=0
```

| Parameter | Type | Description |
|-----------|------|-------------|
| `path` | `string` | The drafted page. Required |
| `offset` | `integer` | Where to start, in characters. Defaults to 0 |
| `length` | `integer` | How many characters to read, up to 30,000. Defaults to 12,000 |

Returns `{ ok: true, path, revision, offset, totalChars, more, markup }`. `more: true` means the page continues.

### Edit a draft

```
PATCH /api/v1/storefront/drafts
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `path` | `string` | Yes | The drafted page |
| `edits` | `{ oldText, newText }[]` | Yes | 1–20 replacements, applied in order, all or none. Each `oldText` must match exactly once |

Scripts, event handlers and `<style>` blocks are refused. An edit that fits another drafted page exactly, such as a shared header, lands there too and is listed in `alsoChanged`.

Returns `{ ok: true, path, revision, changed, alsoChanged }`.

### List draft changes

```
GET /api/v1/storefront/drafts/changes
```

Every draft change the storefront code does not have yet, as `{ ok: true, changes: [{ page, from, to }] }`. When the merchant confirms their draft changes, make each one in the code. An empty list means nothing is waiting.

---

## Publish the storefront

```
POST /api/v1/storefront/publish
```

Starts a production build of the storefront and answers `202` at once. Nothing is live until [the publish](#get-a-publish) reports `live`.

| Field | Type | Description |
|-------|------|-------------|
| `source` | `"workspace" \| "remote"` | `workspace` (default) saves the workspace's edits to `main` and publishes that commit, as the Design page's **Publish** button does. `remote` deploys the commit `main` points at without reading the workspace, for callers that push to git themselves |
| `message` | `string` | Commit message for the save, such as `feat(home): autumn banner`. When the save commits, the change is also recorded in the store's version history under this message. `workspace` only |
| `expectedSha` | `string` | The full 40-character SHA you expect on `main`. The publish is refused with `409` when `main` is anywhere else. `remote` only |
| `skipIfLive` | `boolean` | When the live site already serves the commit and a workspace publish found nothing new to save, answer `200` `already_live` instead of rebuilding |

```bash
curl -X POST \
  -H "Authorization: Bearer sk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"message":"feat(home): autumn banner"}' \
  https://your-store.yns.store/api/v1/storefront/publish
```

### Response (202)

```json
{
  "publishId": "019642c4-699d-729a-b606-0000000000a1",
  "status": "queued",
  "commitSha": "191fe446aa98ce1bced97585adbb910d7ebbeebb",
  "deploymentId": null,
  "deploymentUrl": null,
  "inspectorUrl": null,
  "savedChanges": true,
  "managedFilesRestored": [],
  "liveUrl": "https://acmecandles.com",
  "versionId": "019642c4-699d-729a-b606-0000000000b7"
}
```

| Field | Description |
|-------|-------------|
| `publishId` | Poll [Get a publish](#get-a-publish) with it |
| `commitSha` | The commit being deployed |
| `deploymentId`, `deploymentUrl`, `inspectorUrl` | `null` until the build has a deployment |
| `savedChanges` | `true` only when a workspace publish saved new work |
| `managedFilesRestored` | Platform-managed files whose workspace edits the save discarded. Those edits are not in this publish |
| `liveUrl` | The store's public address |
| `versionId` | The version history entry the save recorded, when you sent a `message` |

With `skipIfLive` and nothing to build, the answer is `200` with `"status": "already_live"`, `"publishId": null` and a `serving` object (`state` is `serving`, `not_serving` or `unknown`). Check `serving`: a paused store serves nothing.

### Errors

| Status | Description |
|--------|-------------|
| `400` | The store is not served from a platform-created project, or the body is invalid: `expectedSha` with `source: "workspace"`, or `message` with `source: "remote"` |
| `403` | The team member behind an OAuth connection may not change the design |
| `409` | Publishing is blocked right now: a publish is already running, `main` is not at `expectedSha`, or for `source: "workspace"` the workspace is asleep, was never opened, or its save lost a race. `error` says which. Retry after it clears |

## Get a publish

```
GET /api/v1/storefront/publish/:publishId
```

Poll every few seconds until `status` is `live`, `domain_pending` or `failed`. Before that it is `queued`, `building` or `verifying`.

```json
{
  "publishId": "019642c4-699d-729a-b606-0000000000a1",
  "status": "live",
  "readyState": "READY",
  "deploymentId": "dpl_abc123",
  "url": "store-abc123.vercel.app",
  "commitSha": "191fe446aa98ce1bced97585adbb910d7ebbeebb",
  "reason": null
}
```

Only `live` means the store's addresses serve the new build. `readyState: "READY"` means the build finished, not that it is live. `reason` explains `domain_pending` and `failed`. The [Publish](/docs/api-reference/publish) page describes every status.

| Status | Description |
|--------|-------------|
| `400` | The store is not served from a platform-created project |
| `404` | No such publish, or a newer publish replaced it |

## Related

- [Publish](/docs/api-reference/publish) – the deprecated `/api/v1/publish` endpoints
- [MCP Server](/docs/api-reference/mcp-server) – the same operations as MCP tools