ShopdeskDevelopers
shopdeskbd.com

Design a storefront with AI

Read the section catalogue, write a page draft, set colours and fonts, and publish in two steps.

An assistant can design a merchant's storefront: read the theme, pick sections from the catalogue, write a page, set the brand colours and fonts, and put the result live once the merchant has seen what changes. This guide walks the five calls that do it, over the store MCP server and over REST, and the rules that keep a merchant's live shop safe while it happens.

You need a key with the storefront scopes the job calls for:

ScopeLets the keyEnough for
storefront:readRead the design, the section catalogue, pages, revisions, theme settings, menus and the media library, and dry-run a treeLooking and planning
storefront:writeCreate pages, change page drafts and the theme-settings draft, import images. Nothing reaches shoppersDrafting a design for the merchant to finish in the dashboard
storefront:publishPut a page draft or the theme settings live, roll a page back, save a menu — each after a preview and a confirmation. Granted only together with storefront:readGoing live

storefront:write satisfies storefront:read, but never storefront:publish: a key that edits drafts cannot put anything live. Mint a write-only key when the merchant wants to review the work in the dashboard before it goes out. media:generate lets a key generate images with AI into the media library, at 2 of the store's AI credits per image; it is granted only together with storefront:write and implies no storefront scope. See Scopes.

Every endpoint is under /ext/v1/storefront/ and listed in the Storefront reference. A company-scoped key passes store_id, because a design belongs to one store. A store with no active theme answers every call with 409 NO_ACTIVE_THEME, except GET /storefront/design, which answers theme: null and says so in notes.

The five calls

Over the store MCP server the whole job is five tools, in this order:

  1. get_store_design — the store, the active theme, the live colour and font tokens, every page with its publish state, the menus, the media count and the section catalogue by category. Make this call first.
  2. list_sections — every section a page may hold, one compact row each, filterable by category, page_type or search.
  3. get_section_schema — the full settings and blocks of 1 to 5 sections as JSON Schema, with their defaults and the colour token names.
  4. save_page_draft — writes a page's whole draft. For a change to one section, update_page_sections applies up to 50 operations instead.
  5. publish_page, twice — once for a preview, once with its confirmation_token to go live.

The REST calls are the same steps, shown below in four languages.

1. Read the design

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS "https://api.shopdeskbd.com/ext/v1/storefront/design" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY"

pages lists the design pages of the active theme: system pages (home, product, collection, cart, search, …), custom pages and the layout page that holds the header and footer. Each row says whether it has unpublished changes, when it was last published and who changed it last. Popups and landing pages are never listed, and their ids answer 404 on every storefront endpoint: the API designs the theme's pages only.

To find a page by what it is rather than its id, filter the list — GET /storefront/pages?system_key=home, or ?handle= for a custom page — then read it by id. GET /storefront/pages/{id} takes an id only. The MCP get_page tool does both steps for you: it takes page_id, system_key or handle.

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS "https://api.shopdeskbd.com/ext/v1/storefront/pages?system_key=home" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY"

Read the page with include=summary to see only its outline, draft (the default) for the draft tree, published for the live one, or both. Keep its draft_updated_at: the next write sends it back.

2. Choose sections

GET /storefront/sections is the catalogue: a slug, a name, a category, a one-line description, the page context it needs (contexts: product, collection, cart or search), where it may be placed (surfaces), its latest version and its status. A deprecated section may stay on a page that already has it, but cannot be added.

Before writing a section's settings, read its schema:

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS "https://api.shopdeskbd.com/ext/v1/storefront/sections/cta_section" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY"

schema.settings is a JSON Schema object and schema.blocks lists the block types with their min and max; shared sub-schemas sit in $defs at the root. defaults is a valid starting point, and token_names are the names a token:<name> colour value may use. The MCP tool get_section_schema takes up to 5 slugs and returns them in the order asked; an unknown slug fails the call with NOT_FOUND.

Write settings exactly as the schema spells them: a key the schema does not have is refused (UNKNOWN_SETTING) rather than dropped, so a typo never vanishes silently.

3. Write the draft

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X PUT "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_PAGE_ID/draft" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: REPLACE_WITH_A_UUID" \
  -H "Content-Type: application/json" \
  -d '{
  "tree": {
    "schema": 1,
    "sections": [
      {
        "id": "s_3f2b8c1e9d4a",
        "type": "cta_section",
        "version": "1",
        "settings": {
          "heading": "Eid collection — new arrivals",
          "cta_label": "Shop the collection",
          "cta_link": {
            "type": "url",
            "url": "/products"
          },
          "image": "asset:placeholder-hero",
          "overlay": "soft"
        },
        "blocks": []
      }
    ]
  },
  "base_draft_updated_at": "2026-11-09T10:00:00.000Z"
}'

A tree is { schema: 1, sections: [...] }; the layout page holds { schema: 1, groups: {...} }. A tree without schema: 1 is refused as malformed. Each section carries an id, its type (the slug), a version, settings and blocks. Ids are opaque strings, unique within the tree (s_hero_cta is fine); the ids the API makes when update_page_sections inserts a node are s_ for a section or b_ for a block followed by 12 lower-case hex characters, such as s_3f2b8c1e9d4a. version is the section's major version as a string ("1"), and settings use exactly the keys its schema lists.

The save replaces the whole draft and is checked first: an error refuses the save, and error.fields is keyed by JSON pointer into the tree, each entry listing the codes it broke. Warnings come back with a successful save. POST /storefront/pages/{id}/validate (the MCP validate_page_tree) runs the same checks and writes nothing; it needs only storefront:read and counts as a read (x-metered-as: read).

Don't overwrite someone else's work. Send the draft_updated_at you read as base_draft_updated_at. If the draft changed since — the merchant saved in the editor, say — the write is refused with 409 DRAFT_CONFLICT, and error.fields.base_draft_updated_at carries the current value. Read the page again and redo the change. Leaving it out writes regardless.

Change one section without resending the page with PATCH /storefront/pages/{id}/draft (update_page_sections): up to 50 operations — insert, replace, remove or move a section, merge its settings, replace its blocks, merge one block's settings — applied in order and saved as a whole, or not at all. A refused operation is named in error.fields['operations/<index>']. A shared header or footer section can be moved, hidden or removed there, never edited.

New page. POST /storefront/pages (create_page) creates a custom page at /pages/<handle>, with an empty draft or a tree. Only custom pages can be created; a handle already taken is 409 CONFLICT on fields.handle.

What the API refuses

These rules apply to every tree the API saves, on top of each section's schema. Each is an error that refuses the save, except where the table says otherwise:

CodeRule
LINK_SCHEMEA link url must be https:, http:, mailto:, tel:, a site path (/…) or a same-page # anchor.
ASSET_ORIGINAn image value (asset:…) must be a theme asset or a file in the store's own media storage; one pointing anywhere else is refused. Import it first (below).
RICHTEXT_SANITIZEDA warning, not a refusal: rich text held tags, attributes or image origins outside the allowed set, and the cleaned value is what was saved.
COMPONENT_DEPRECATEDA deprecated section stays where it already was; a new one is refused, naming its replacement.
TREE_TOO_LARGEAt most 60 sections (per layout group on the layout page), 300 blocks at all depths and 512 KB per tree.
STRING_TOO_LONGA text field without its own limit takes 5,000 characters, rich text 20,000.
SHARED_REF_KEPTA shared header or footer section may be kept, moved or removed, never added to a page that does not have it.
FEATURE_LOCKEDA setting that needs a plan feature the store does not have must stay at its default.
UNKNOWN_SETTINGA settings key that is not in the section's (or block's) schema.

Colours and fonts

GET /storefront/theme-settings (get_theme_settings) returns the live tokens — colours, fonts, radius, spacing — the draft if there is one, and the schema a write must follow: the brand colour families, the font slots and ids, the radius and spacing keys. They belong to the theme the store has active and are shared by every page.

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X PUT "https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/draft" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: REPLACE_WITH_A_UUID" \
  -H "Content-Type: application/json" \
  -d '{
  "settings": {
    "colors": {
      "primary": "#0f766e"
    }
  },
  "mode": "merge"
}'

mode: "merge" (the default) merges settings into the current draft, or into the live tokens when there is no draft; replace makes settings the whole draft, which must then hold every live colour family, font slot, radius and spacing key. A refused token is named by JSON pointer. The draft goes live with POST /storefront/theme-settings/publish (publish_theme_settings), in the same two steps as a page.

Images

An image setting takes a media-library asset. Bring images in by link:

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/media/import" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: REPLACE_WITH_A_UUID" \
  -H "Content-Type: application/json" \
  -d '{
  "images": [
    {
      "url": "https://cdn.example.com/banners/eid.jpg",
      "name": "eid-banner"
    }
  ]
}'

POST /storefront/media/import (import_media_from_urls) downloads up to 10 https images (PNG, JPEG, WebP or GIF, at most 10 MB and 8000 px) into the library at once — no page changes until one that uses them is published — through the same checks as Photos by link, all of them or none. Each answer item's asset is the value to put in an image setting. The library holds at most 2,000 items: an import that would pass it is 422 VALIDATION_ERROR with fields.images = ["media_library_cap_2000"]. GET /storefront/media (list_media) pages through what is already there.

Generate an image

With media:generate, POST /storefront/media/generate (generate_image) makes one image with AI from a prompt (1 to 1,000 characters) and an aspect: square (the default, 1024×1024), landscape (1536×1024) or portrait (1024×1536). name is optional. It costs 2 of the store's AI credits per image, refunded when nothing is produced, and a store can make 30 a day. The Idempotency-Key header (idempotency_key on the tool) is required: without it the answer is 400 VALIDATION_ERROR, and a retry with the same key returns the same image without a second charge. The answer carries the library item, whose asset goes into an image setting, plus model, width, height and credits. Nothing shoppers see changes until a page that uses it is published. A prompt the provider's safety filter refuses is 422 VALIDATION_ERROR with fields.prompt = ["rejected"] and costs nothing; the other answers are listed under Errors.

4. Publish in two steps

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_PAGE_ID/publish" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "message": "Eid banner"
}'

The first call changes nothing. It answers status: "preview" with a summary of what would go live — for a page, the sections added, removed, changed and moved — first_publish: true (beside summary) when the page has never been live, and a single-use confirmation_token that lasts 10 minutes. A draft that already matches the live page answers no_changes and no token. Show the summary to the merchant, then confirm:

export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_PAGE_ID/publish" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: REPLACE_WITH_A_NEW_UUID" \
  -H "Content-Type: application/json" \
  -d '{
  "confirmation_token": "REPLACE_WITH_THE_PREVIEW_TOKEN",
  "message": "Eid banner"
}'

The confirm carries the token and an Idempotency-Key header (on MCP, the idempotency_key argument): without one it is refused with fields.idempotency_key = ["required_with_confirmation_token"], so a retry after a lost answer replays instead of publishing twice. Use a fresh key for the confirm: a preview sent with an Idempotency-Key stores its answer under that key, and the confirm is a different request. The answer is status: "published".

Undo. GET /storefront/pages/{id}/revisions (list_page_revisions) lists a page's published revisions, the live one marked. POST /storefront/pages/{id}/rollback (rollback_page) is not a preview: its first call copies the revision into the draft at once, replacing the current draft (status: "restored") — save or publish unpublished work first. Shoppers still see the live page. With publish: true the same answer also carries the preview of publishing the restored draft and its token. Confirm it with a second call to the rollback route (rollback_page): the same page and revision_id, the token and a fresh Idempotency-Key (idempotency_key on MCP). A rollback token sent to POST …/publish (publish_page) is refused as unknown_or_expired and used up.

Menus have no draft: a saved menu is what shoppers see. So PUT /storefront/menus/{handle} (save_menu) is a publish — it needs storefront:publish and takes the same two steps. Send the same body on the preview and the confirm: the token is bound to it, and a different body is PREVIEW_STALE. A menu holds at most 4 levels and 250 items, its links follow LINK_SCHEME, and a section's menu setting takes menu:<handle>.

With the store MCP server

Each step above is one tool. The design tools change drafts (and the media library, which generate_image adds to) only, except the four that take storefront:publish. publish_page, publish_theme_settings and save_menu preview first and go live only on a second call with the confirmation_token; rollback_page restores the revision into the draft on its first call, and only publishing it (publish: true) takes the two steps. An assistant should show the merchant the preview's summary before any confirm. The full list is in Build with AI, and every tool's arguments are on MCP tools.