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

CallerAccess
Store API keyNeeds the store:admin scope.
OAuth connectionThe 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

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.

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

Response (200)

{
"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)

FieldDescription
workspaceReadablefalse when the workspace could not be read. unsavedChanges and changedFiles are then unknown, not clean.
workspaceread, stopped (the workspace is asleep, so nothing in it is unsaved) or unreachable
unsavedChanges, changedFilesEdits made since the last save. The preview shows them; the live site cannot have them.
managedEditsThe part of changedFiles that is platform-managed. The next publish discards those edits.
setAsideEditsEdits set aside because the code changed outside the Design page. They are neither in the preview nor live.
lastPublishLiveThe last publish landed and the public address serves it. Edits made since are in changedFiles.
publishedfalse when the store is switched off and its public addresses show the "Coming soon" page
liveUrlThe 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
draftShaThe commit the workspace is at
building{ readyState, commitSha, startedAt } while a publish is still building, otherwise null
lastPublishHow the last publish ended, with its reason when it failed

Read a file

GET /api/v1/storefront/files?path=src/app/(store)/page.tsx
ParameterTypeDescription
pathstringFile path relative to the project root. Required.

Response (200)

{
"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.

FieldTypeRequiredDescription
pathstringYesFile path relative to the project root
contentstringYesThe whole new content, up to 1,000,000 characters
baseVersionstringNoThe version you read the file at. The write is refused with 409 when the file changed since. Leave it out to write regardless
{ "path": "src/components/banner.tsx", "version": "51ab…07c3" }
StatusDescription
409The 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.

FieldTypeRequiredDescription
pathstringYesFile path relative to the project root
oldTextstringYesExact text to replace. It must occur in the file exactly once, so quote enough around the spot to make it unique
newTextstringYesWhat to put in its place
baseVersionstringNoThe version you read the file at
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 }.

StatusDescription
400oldText does not occur in the file exactly once. Nothing changed
404No such file
409The 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 for a type check or a build.

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

FieldTypeRequiredDescription
commandstringYesThe bash command, up to 4,000 characters
{ "stdout": "src/components/hero.tsx:12: <h1>Summer sale</h1>\n", "stderr": "", "exitCode": 0 }
StatusDescription
400The command touches secrets
403Called 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.

FieldTypeRequiredDescription
check"typecheck" | "lint" | "build"Yestypecheck runs bun tsc --noEmit, lint runs biome check without changing files, build runs bun run build, which is what a publish runs
{ "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.

stateMeaning
runningStill running
finishedDone. exitCode 0 means it passed. The errors are at the end of output. 124 means it was stopped after 8 minutes
lostThe 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.

FieldTypeDescription
pathstringA page of the store, such as / or /product/ocean-bloom. Defaults to the homepage
devicestringdesktop, 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:

HeaderDescription
X-Screenshot-PathThe page
X-Screenshot-ViewportThe browser window, WxH
X-Screenshot-SizeThe image, WxH. Smaller than the window when it had to shrink
X-Screenshot-DeviceThe 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.

FieldTypeDescription
pathstringA page of the store. Defaults to the homepage
{ "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.

{
"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
ParameterTypeDescription
querystringExact text or markup to find. Case is ignored. Required
pathstringSearch 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
ParameterTypeDescription
pathstringThe drafted page. Required
offsetintegerWhere to start, in characters. Defaults to 0
lengthintegerHow 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
FieldTypeRequiredDescription
pathstringYesThe drafted page
edits{ oldText, newText }[]Yes1–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 reports live.

FieldTypeDescription
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
messagestringCommit 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
expectedShastringThe full 40-character SHA you expect on main. The publish is refused with 409 when main is anywhere else. remote only
skipIfLivebooleanWhen the live site already serves the commit and a workspace publish found nothing new to save, answer 200 already_live instead of rebuilding
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)

{
"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"
}
FieldDescription
publishIdPoll Get a publish with it
commitShaThe commit being deployed
deploymentId, deploymentUrl, inspectorUrlnull until the build has a deployment
savedChangestrue only when a workspace publish saved new work
managedFilesRestoredPlatform-managed files whose workspace edits the save discarded. Those edits are not in this publish
liveUrlThe store's public address
versionIdThe 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

StatusDescription
400The store is not served from a platform-created project, or the body is invalid: expectedSha with source: "workspace", or message with source: "remote"
403The team member behind an OAuth connection may not change the design
409Publishing 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.

{
"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 page describes every status.

StatusDescription
400The store is not served from a platform-created project
404No such publish, or a newer publish replaced it
  • Publish – the deprecated /api/v1/publish endpoints
  • MCP Server – the same operations as MCP tools