Search Documentation
Search for a documentation page...
Storefront Code API
Read and edit an AI-built storefront's source code, run commands and checks, take screenshots, edit page drafts and publish the result.
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.
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 is the one exception: it takes the store API key only, and an OAuth connection gets 403.
Open the 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.
Response (200)
Get the storefront status
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
| Parameter | Type | Description |
|---|---|---|
path | string | File path relative to the project root. Required. |
Response (200)
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
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 |
| Status | Description |
|---|---|
409 | The file changed since baseVersion, or no longer exists. Read it again |
Edit a file
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 |
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
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 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 |
| Status | Description |
|---|---|
400 | The command touches secrets |
403 | Called over OAuth instead of with the store API key |
Start a check
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 |
Get a check
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
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
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 |
Find catalog data in the code
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.
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
| 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
| 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
| 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
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
Starts a production build of the storefront and answers 202 at once. Nothing is live until the 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 |
Response (202)
| Field | Description |
|---|---|
publishId | Poll 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
Poll every few seconds until status is live, domain_pending or failed. Before that it is queued, building or verifying.
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 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 – the deprecated
/api/v1/publishendpoints - MCP Server – the same operations as MCP tools