# Storefront

Part of the [Shopdesk Commerce API reference](https://www.shopdeskbd.com/developers/reference.md). Paths below are shown exactly as the server routes them — prefix them with `https://api.shopdeskbd.com`. Authenticate every request with `Authorization: Bearer shopdesk_sk_YOUR_API_KEY`; each operation names the scope its key must hold. Every failure uses the one error envelope — see [Errors](https://www.shopdeskbd.com/developers/errors.md).

## Get the store design

`GET /ext/v1/storefront/design` · Requires scope `storefront:read`

The one call to make first: the store (name, currency), the active theme, the live design tokens, every page with its publish state and last change, the menus, the media count, the section catalogue by category and the product, category and brand counts. A store with no active theme answers `theme: null` and says so in `notes`. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |

### Request

**cURL**

```bash
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"
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/design");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/design",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/design');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The design.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "store": {
    "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
    "name": "Dhaka Threads",
    "currency": "BDT"
  },
  "theme": {
    "slug": "fashion",
    "name": "Fashion",
    "version": "1.4.0"
  },
  "tokens": {
    "live": {},
    "has_draft": false
  },
  "pages": [
    {
      "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
      "type": "system",
      "system_key": "home",
      "handle": "about-us",
      "title": "Home",
      "status": "active",
      "has_unpublished_changes": false,
      "published_at": "2026-08-11T10:00:00.000Z",
      "draft_updated_at": "2026-08-11T10:00:00.000Z",
      "last_change": {
        "at": "2026-08-11T10:00:00.000Z",
        "via": "api",
        "actor_name": "Nusrat Jahan",
        "api_key_label": "Design assistant"
      }
    }
  ],
  "menus": [
    {
      "handle": "main-menu",
      "name": "Main menu",
      "item_count": 6
    }
  ],
  "media_count": 42,
  "catalog_summary": {
    "categories": [
      {
        "category": "hero",
        "count": 7
      }
    ]
  },
  "counts": {
    "products": 120,
    "categories": 14,
    "brands": 6
  },
  "notes": []
}
```

## List the media library

`GET /ext/v1/storefront/media` · Requires scope `storefront:read`

The company's storefront images, sorted by key and paged with `starting_after` (the previous page's `next_cursor`). Each item's `asset` is the value an `image` field takes. `search` matches the file name. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |
| `limit` | `number` (default `50`, max 100) | No | Page size. |
| `starting_after` | `string` | No | Return the page AFTER this item's `key` (the previous page's `next_cursor`). |
| `search` | `string` | No | Case-insensitive substring of the file name. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS "https://api.shopdeskbd.com/ext/v1/storefront/media?limit=25" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY"
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/media");
Object.entries({
  limit: "25",
}).forEach(([key, value]) => url.searchParams.set(key, value));

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data, meta } = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/media",
    params={
        "limit": "25",
    },
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows, meta = page["data"], page["meta"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/media?limit=25');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
$meta = $response['meta'];
```

### Responses

- `200` — A page of media items.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.
- `502` — `STORAGE_UNAVAILABLE`: the media storage refused or was unreachable — retry in a moment.

**Example 200 response**

```json
{
  "data": [
    {
      "key": "companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp",
      "name": "banner-1700000000.webp",
      "url": "https://cdn.example.com/companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp",
      "size": 182344,
      "uploaded_at": "2026-08-11T10:00:00.000Z",
      "asset": "asset:companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp"
    }
  ],
  "meta": {
    "has_more": true,
    "next_cursor": "companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp"
  }
}
```

## Generate an image with AI

`POST /ext/v1/storefront/media/generate` · Requires scope `media:generate`

Generates ONE image with AI from `prompt` and stores it in the company's media library (it counts toward the 2,000-item cap). Each image costs 2 of the store's AI credits, handed back when nothing is produced; a store makes at most 30 a day. `aspect` picks 1024×1024 (`square`, the default), 1536×1024 (`landscape`) or 1024×1536 (`portrait`). The answer's `data.asset` is the value an `image` field takes; nothing shoppers see changes until a page using it is published. `Idempotency-Key` is required: a retry with the same key returns the same image without a second charge. Needs `media:generate`, which is granted only beside `storefront:write`. Company-scoped keys pass `store_id` in the body.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | Yes | REQUIRED. A unique value per logical request (a UUID is ideal); reuse it verbatim when retrying. A retry replays the original response with `Idempotent-Replayed: true` instead of running twice. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `prompt` | `string` | Yes | What the image shows, 1–1,000 characters after trimming. Sent to the AI provider. |
| `aspect` | `string` (default `square`) | No | `square` (1024×1024, the default), `landscape` (1536×1024) or `portrait` (1024×1536). One of: `square`, `landscape`, `portrait`. |
| `name` | `string` | No | The file name in the library (made safe, prefixed `ai-`, then timestamped); the prompt's start when left out. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/media/generate" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "prompt": "A warm Eid banner: lanterns and crescent moon over a soft gold background, no text",
  "aspect": "landscape",
  "name": "eid-banner"
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/media/generate");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "prompt": "A warm Eid banner: lanterns and crescent moon over a soft gold background, no text",
    "aspect": "landscape",
    "name": "eid-banner"
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data } = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "prompt": "A warm Eid banner: lanterns and crescent moon over a soft gold background, no text",
    "aspect": "landscape",
    "name": "eid-banner",
}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/media/generate",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows = page["data"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'prompt' => 'A warm Eid banner: lanterns and crescent moon over a soft gold background, no text',
    'aspect' => 'landscape',
    'name' => 'eid-banner',
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/media/generate');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
```

### Responses

- `201` — The generated image, the model that made it, and its cost.
- `400` — The required `Idempotency-Key` header is missing, empty, or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key lacks `media:generate` (`FORBIDDEN_SCOPE`); the company's plan does not include the AI assistant (`PLAN_FEATURE_REQUIRED`); AI image generation is switched off (`IMAGE_GENERATION_DISABLED`, `error.fields.reason = ['platform']` or `['store']`); or the company has used all of its AI credits for this billing period, shared by its stores (`AI_CREDITS_EXHAUSTED`).
- `409` — the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — The body is not valid (`VALIDATION_ERROR`, `error.fields` names the field); the AI provider's safety filter refused the prompt (`error.fields.prompt = ['rejected']`, nothing charged); or the library would pass 2,000 items (`error.fields.media_library = ['media_library_cap_2000']`).
- `429` — The store has made today's 30 images, or the key's write limit (`RATE_LIMITED`, with `Retry-After`).
- `502` — `STORAGE_UNAVAILABLE`: the media storage refused or was unreachable — retry in a moment.
- `503` — No image could be made (`AI_UNAVAILABLE`): no AI image model is set up on this platform yet (`error.fields.reason = ['no_image_provider']`; a configuration state, so retrying does not help until one is set up) or the provider failed (`['provider_failed']`; retry later). Nothing stays charged.

**Example 200 response**

```json
{
  "data": {
    "key": "companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp",
    "name": "banner-1700000000.webp",
    "url": "https://cdn.example.com/companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp",
    "size": 182344,
    "uploaded_at": "2026-08-11T10:00:00.000Z",
    "asset": "asset:companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp"
  },
  "model": "gpt-image-2.5-flare",
  "width": 1024,
  "height": 1024,
  "credits": 2
}
```

## Import images into the media library

`POST /ext/v1/storefront/media/import` · Requires scope `storefront:write`

Downloads up to 10 images by https link and stores them in the company's media library — all of them, or none. Each answer item's `asset` is the value an `image` field takes. The API adds images only while the library stays at or under 2,000 items. Image links: https only, PNG/JPEG/WebP/GIF read from the bytes (never SVG), at most 10 MB and 8000 px on the longest side (and 40 megapixels in all; 16 for a GIF), fetched within 10 s each and 30 s for the call, at most 50 MB downloaded per call. One failing link fails the whole call and nothing is written. Each image a call carries — link or file — counts as one write against the key's per-minute write limit; calls that download or upload images run at most 2 at a time per key; and a company may have 2,000 links downloaded per UTC day. Past any of these the answer is `429 RATE_LIMITED` with `Retry-After`. Company-scoped keys pass `store_id` in the body.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `images` | `StorefrontMediaImportEntryDto[]` | Yes | Up to 10 images, stored all or none. |

### `images[]` fields

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | `string` | Yes | The https link to download. |
| `name` | `string` | No | The file name in the library (made safe, then timestamped); the link's own file name when left out. |

### Request

**cURL**

```bash
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: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "images": [
    {
      "url": "https://cdn.example.com/banners/eid.jpg",
      "name": "eid-banner"
    }
  ]
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/media/import");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "images": [
      {
        "url": "https://cdn.example.com/banners/eid.jpg",
        "name": "eid-banner"
      }
    ]
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data } = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "images": [
        {
            "url": "https://cdn.example.com/banners/eid.jpg",
            "name": "eid-banner",
        },
    ],
}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/media/import",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows = page["data"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'images' => [
        [
            'url' => 'https://cdn.example.com/banners/eid.jpg',
            'name' => 'eid-banner',
        ],
    ],
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/media/import');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
```

### Responses

- `201` — The stored images, in request order.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — A link was refused or is not an image (`error.fields` names it, `images[<index>].url`), or the library would pass 2,000 items (`error.fields.images = ['media_library_cap_2000']`) (`VALIDATION_ERROR`).
- `429` — Too many image calls by this key at once, its write limit, or the company's daily link budget (`RATE_LIMITED`, with `Retry-After`).
- `502` — `STORAGE_UNAVAILABLE`: the media storage refused or was unreachable — retry in a moment.

**Example 200 response**

```json
{
  "data": [
    {
      "key": "companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp",
      "name": "banner-1700000000.webp",
      "url": "https://cdn.example.com/companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp",
      "size": 182344,
      "uploaded_at": "2026-08-11T10:00:00.000Z",
      "asset": "asset:companies/5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001/media/banner-1700000000.webp"
    }
  ]
}
```

## List the menus

`GET /ext/v1/storefront/menus` · Requires scope `storefront:read`

The navigation menus with their items (`include_items=false` for handles, names and item counts only). Company-scoped keys must pass `store_id`: a design belongs to one store.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |
| `include_items` | `boolean` (default `true`) | No | Pass `false` for handles, names and counts only. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/menus");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data } = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/menus",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows = page["data"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/menus');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
```

### Responses

- `200` — The menus.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "data": [
    {
      "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
      "handle": "main-menu",
      "name": "Main menu",
      "item_count": 6,
      "updated_at": "2026-08-11T10:00:00.000Z"
    }
  ]
}
```

## Save a menu

`PUT /ext/v1/storefront/menus/{handle}` · Requires scope `storefront:publish`

Creates the menu with this handle, or replaces its items (and name). Menus have no draft — a saved menu is live at once — so this is a publish, in two calls. First call WITHOUT `confirmation_token`: nothing changes; the answer is a `preview` with a `summary` of what would go live and a single-use `confirmation_token` (10 minutes), or `no_changes` (no token). Show the summary to a person; then call again with the token AND an `Idempotency-Key` header to publish. If what was previewed changed in between, the confirm is refused (`409 PREVIEW_STALE`): preview again. A confirm uses its token up once it reaches the token check; a confirm refused earlier — for a missing `Idempotency-Key`, a 404/409 from the fence, or (menus) item validation — leaves it usable. Send the same body both times: the token is bound to it. The preview lists the items added, removed, relabelled, retargeted and moved. Company-scoped keys pass `store_id` in the body.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `handle` | `string` | Yes | The menu handle (lowercase letters, digits and hyphens), from `GET /storefront/menus`; a new one creates the menu. |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `confirmation_token` | `string` | No | Leave it out to get a preview and a token. Send the token from that preview (with an `Idempotency-Key` header) to confirm: it is single-use and lives 10 minutes. |
| `name` | `string` | No | The menu's name. Required when the handle is new (the menu is created); left out, an existing menu keeps its name. |
| `items` | `object[]` | Yes | The whole item tree, replacing the current one: `{ id?, label, link: { type: 'none' \| 'url' \| 'product' \| 'category' \| 'page', id?, url? }, children? }`, at most 4 levels and 250 items, labels up to 120 characters. Keep an item's `id` to keep it; an item without one is new. A `url` must be https, http, mailto, tel, a site path or a `#` fragment; a product, category or page id must exist in the store. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X PUT "https://api.shopdeskbd.com/ext/v1/storefront/menus/REPLACE_WITH_ID" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Main menu",
  "items": [
    {
      "label": "New arrivals",
      "link": {
        "type": "url",
        "url": "/collections/new"
      }
    },
    {
      "label": "About us",
      "link": {
        "type": "page",
        "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a002"
      }
    }
  ]
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/menus/REPLACE_WITH_ID");

const response = await fetch(url, {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "Main menu",
    "items": [
      {
        "label": "New arrivals",
        "link": {
          "type": "url",
          "url": "/collections/new"
        }
      },
      {
        "label": "About us",
        "link": {
          "type": "page",
          "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a002"
        }
      }
    ]
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "name": "Main menu",
    "items": [
        {
            "label": "New arrivals",
            "link": {
                "type": "url",
                "url": "/collections/new",
            },
        },
        {
            "label": "About us",
            "link": {
                "type": "page",
                "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a002",
            },
        },
    ],
}

response = requests.put(
    "https://api.shopdeskbd.com/ext/v1/storefront/menus/REPLACE_WITH_ID",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'name' => 'Main menu',
    'items' => [
        [
            'label' => 'New arrivals',
            'link' => [
                'type' => 'url',
                'url' => '/collections/new',
            ],
        ],
        [
            'label' => 'About us',
            'link' => [
                'type' => 'page',
                'id' => '5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a002',
            ],
        ],
    ],
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/menus/REPLACE_WITH_ID');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The preview, the saved menu, or `no_changes`.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — What was previewed changed before the confirm (`PREVIEW_STALE`: ask for a new preview), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — An item is refused (`error.fields['items/<i>/…']`: `LINK_SCHEME` for a link that is not https, http, mailto, tel, a site path or a `#` fragment; `unknown_target` on `items/<i>/link` for a product, category or page this store does not have; `invalid` or `too_many_items` otherwise), a new menu has no `name` (`error.fields.name = ['required_for_new_menu']`), the handle is not one, or the token is unknown, expired, not this key's or from another route's preview (`error.fields.confirmation_token = ['unknown_or_expired']`), or a token came without an `Idempotency-Key` header (`error.fields.idempotency_key = ['required_with_confirmation_token']`) (`VALIDATION_ERROR`).
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "status": "preview",
  "subject": "page:5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "summary": null,
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "confirmation_token": "a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8",
  "expires_at": "2026-08-11T10:00:00.000Z",
  "revision_id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "revision_version": 4,
  "published_at": "2026-08-11T10:00:00.000Z",
  "first_publish": false,
  "menu": {
    "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
    "handle": "main-menu",
    "name": "Main menu",
    "item_count": 6,
    "items": [
      {
        "id": "mi-1",
        "label": "Shirts",
        "link": {
          "type": "category",
          "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
          "url": "https://example.com/sale"
        },
        "children": [
          {}
        ]
      }
    ],
    "updated_at": "2026-08-11T10:00:00.000Z"
  }
}
```

## Create a page

`POST /ext/v1/storefront/pages` · Requires scope `storefront:write`

A new custom page at `/pages/<handle>` (the handle is made from the title when left out), as an unpublished draft: empty, or `tree`, checked like a draft save. A handle that belonged to a deleted page brings that page back as this new one (`revived: true`). Company-scoped keys pass `store_id` in the body. Nothing changes for shoppers until the page is published.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `title` | `string` | Yes | — |
| `handle` | `string` | No | The address, `/pages/<handle>`: lower-case letters, digits and dashes. Made from the title when left out. |
| `seo` | `StorefrontPageSeoDto` | No | — |
| `tree` | `object` | No | The starting draft, `{ schema: 1, sections: [...] }`; an empty page when left out. Checked like a draft save. |

### `seo` fields

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | `string` | No | The browser tab and search result title. |
| `description` | `string` | No | The search result and link preview description. |
| `image_key` | `string` | No | The share image: a media library `key` (from `GET /storefront/media`). |
| `no_index` | `boolean` | No | Ask search engines not to index the page. It stays publicly reachable. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/pages" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "title": "Eid collection",
  "handle": "eid-collection",
  "seo": {
    "title": "Eid collection — new arrivals"
  },
  "tree": {
    "schema": 1,
    "sections": [
      {
        "id": "s_hero_cta",
        "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": []
      }
    ]
  }
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "title": "Eid collection",
    "handle": "eid-collection",
    "seo": {
      "title": "Eid collection — new arrivals"
    },
    "tree": {
      "schema": 1,
      "sections": [
        {
          "id": "s_hero_cta",
          "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": []
        }
      ]
    }
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "title": "Eid collection",
    "handle": "eid-collection",
    "seo": {
        "title": "Eid collection — new arrivals",
    },
    "tree": {
        "schema": 1,
        "sections": [
            {
                "id": "s_hero_cta",
                "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": [],
            },
        ],
    },
}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'title' => 'Eid collection',
    'handle' => 'eid-collection',
    'seo' => [
        'title' => 'Eid collection — new arrivals',
    ],
    'tree' => [
        'schema' => 1,
        'sections' => [
            [
                'id' => 's_hero_cta',
                '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' => [],
            ],
        ],
    ],
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `201` — The new page.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — The handle is taken by another page (`CONFLICT`, `error.fields.handle`), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — The tree breaks a rule (`VALIDATION_ERROR`): `error.fields` is keyed by JSON pointer into the tree, each holding the finding's codes (`LINK_SCHEME`, `TREE_TOO_LARGE`, `FEATURE_LOCKED`, `REQUIRED`, …) — the same findings `POST /storefront/pages/{id}/validate` lists.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "type": "system",
  "system_key": "home",
  "handle": "about-us",
  "title": "Home",
  "status": "active",
  "has_unpublished_changes": false,
  "published_at": "2026-08-11T10:00:00.000Z",
  "draft_updated_at": "2026-08-11T10:00:00.000Z",
  "last_change": {
    "at": "2026-08-11T10:00:00.000Z",
    "via": "api",
    "actor_name": "Nusrat Jahan",
    "api_key_label": "Design assistant"
  },
  "revived": false,
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ]
}
```

## List the pages

`GET /ext/v1/storefront/pages` · Requires scope `storefront:read`

The pages of the active theme — system pages (home, product, collection, cart, search, …), custom pages and the layout page — with whether each has unpublished changes and who changed it last. Find a page by `system_key` or `handle` here, then read it by id. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |
| `type` | `string` | No | Only pages of this type. One of: `system`, `custom`, `layout`. |
| `system_key` | `string` | No | Only the system page with this key (`home`, `product`, `collection`, `cart`, `search`, …; the layout page is `layout`). |
| `handle` | `string` | No | Only the custom page with this handle. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data } = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows = page["data"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
```

### Responses

- `200` — The pages.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "data": [
    {
      "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
      "type": "system",
      "system_key": "home",
      "handle": "about-us",
      "title": "Home",
      "status": "active",
      "has_unpublished_changes": false,
      "published_at": "2026-08-11T10:00:00.000Z",
      "draft_updated_at": "2026-08-11T10:00:00.000Z",
      "last_change": {
        "at": "2026-08-11T10:00:00.000Z",
        "via": "api",
        "actor_name": "Nusrat Jahan",
        "api_key_label": "Design assistant"
      }
    }
  ]
}
```

## Get a page

`GET /ext/v1/storefront/pages/{id}` · Requires scope `storefront:read`

One page with its SEO and layout mode, and by `include`: the draft tree (default), the published tree, both, or a compact `summary` of its sections. Parts not asked for are null. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |
| `include` | `string` (default `draft`) | No | `draft` (default) returns the draft tree; `published` the live tree (null if never published); `both` both; `summary` only the section outline (ids, types, versions, visibility, block counts), for orienting on a big page. Parts not asked for are null. One of: `draft`, `published`, `both`, `summary`. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The page.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store. Popups and landing pages are not served here.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "type": "system",
  "system_key": "home",
  "handle": "about-us",
  "title": "Home",
  "status": "active",
  "has_unpublished_changes": false,
  "published_at": "2026-08-11T10:00:00.000Z",
  "draft_updated_at": "2026-08-11T10:00:00.000Z",
  "last_change": {
    "at": "2026-08-11T10:00:00.000Z",
    "via": "api",
    "actor_name": "Nusrat Jahan",
    "api_key_label": "Design assistant"
  },
  "seo": null,
  "layout_mode": "theme",
  "published_revision_id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "draft": null,
  "published": null,
  "summary": null
}
```

## Save a page draft

`PUT /ext/v1/storefront/pages/{id}/draft` · Requires scope `storefront:write`

Replaces the page's draft with `tree`, checked first by the same rules `POST …/validate` reports: an error refuses the whole save. Send `base_draft_updated_at` (from the read) so a change made since is not overwritten. The answer has the new `draft_updated_at`, the warnings and an outline of the saved draft. Company-scoped keys pass `store_id` in the body. Nothing changes for shoppers until the page is published.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `tree` | `object` | Yes | The whole draft tree, replacing the stored one — the shape `GET /storefront/pages/{id}` returns as `draft` (`{ schema: 1, sections: [...] }`, or `{ schema: 1, groups: {...} }` on the layout page). |
| `base_draft_updated_at` | `date-time` | No | Optimistic lock: the `draft_updated_at` you read. When it is stale the write is refused with `409 DRAFT_CONFLICT`, and `error.fields.base_draft_updated_at` carries the current value. Leave it out to write regardless. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X PUT "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "tree": {
    "schema": 1,
    "sections": [
      {
        "id": "s_hero_cta",
        "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"
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft");

const response = await fetch(url, {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "tree": {
      "schema": 1,
      "sections": [
        {
          "id": "s_hero_cta",
          "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"
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "tree": {
        "schema": 1,
        "sections": [
            {
                "id": "s_hero_cta",
                "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",
}

response = requests.put(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'tree' => [
        'schema' => 1,
        'sections' => [
            [
                'id' => 's_hero_cta',
                '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',
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The draft was saved.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store. Popups and landing pages are not served here.
- `409` — The draft changed since `base_draft_updated_at` (`DRAFT_CONFLICT`; `error.fields.base_draft_updated_at` carries the current value — read the page again), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — The tree breaks a rule (`VALIDATION_ERROR`): `error.fields` is keyed by JSON pointer into the tree, each holding the finding's codes (`LINK_SCHEME`, `TREE_TOO_LARGE`, `FEATURE_LOCKED`, `REQUIRED`, …) — the same findings `POST /storefront/pages/{id}/validate` lists.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "draft_updated_at": "2026-08-11T10:00:00.000Z",
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "summary": {}
}
```

## Change page sections

`PATCH /ext/v1/storefront/pages/{id}/draft` · Requires scope `storefront:write`

Applies up to 50 section operations to the current draft, in order (insert, replace, remove or move a section; merge its settings; replace its blocks; merge a block's settings), then checks and saves the result as a whole — all or nothing. A refused operation is named in `error.fields['operations/<index>']`. Sections on the layout page name their `group`; a shared header or footer section can be moved, hidden or removed, never edited here. Company-scoped keys pass `store_id` in the body. Nothing changes for shoppers until the page is published.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `operations` | `SectionOperationDto[]` | Yes | Applied in order to the current draft, then checked as a whole: all are saved, or none. |
| `base_draft_updated_at` | `date-time` | No | Optimistic lock: the `draft_updated_at` you read. When it is stale the write is refused with `409 DRAFT_CONFLICT`, and `error.fields.base_draft_updated_at` carries the current value. Leave it out to write regardless. |

### `operations[]` fields

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `op` | `string` | Yes | `insert_section` (`section`, and `after_id` \| `before_id` \| `index`), `replace_section` (`section_id`, `section`), `remove_section` (`section_id`), `move_section` (`section_id`, and a position), `set_section_settings` (`section_id`, `settings` merged, a null value removes the key; `visible`), `set_blocks` (`section_id`, `blocks`), `set_block_settings` (`section_id`, `block_id`, `settings`). On the layout page every operation names its `group`. One of: `insert_section`, `replace_section`, `remove_section`, `move_section`, `set_section_settings`, `set_blocks`, `set_block_settings`. |
| `section_id` | `string` | No | — |
| `block_id` | `string` | No | — |
| `section` | `object` | No | A section node `{ type, version, settings, blocks?, visible? }`; its `id` is generated when absent. |
| `blocks` | `object[]` | No | The section's new blocks, replacing the old ones. |
| `settings` | `object` | No | Settings to merge; a null value removes the key. |
| `visible` | `boolean` | No | — |
| `after_id` | `string` | No | Place after this section id. |
| `before_id` | `string` | No | Place before this section id. |
| `index` | `number` | No | Place at this index (0 is first). |
| `group` | `string` | No | Layout page only: the group (`header`, `footer`, …). |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X PATCH "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "operations": [
    {
      "op": "set_section_settings",
      "section_id": "s_hero_cta",
      "settings": {
        "heading": "Eid sale — 20% off"
      }
    }
  ],
  "base_draft_updated_at": "2026-11-09T10:00:00.000Z"
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft");

const response = await fetch(url, {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "operations": [
      {
        "op": "set_section_settings",
        "section_id": "s_hero_cta",
        "settings": {
          "heading": "Eid sale — 20% off"
        }
      }
    ],
    "base_draft_updated_at": "2026-11-09T10:00:00.000Z"
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "operations": [
        {
            "op": "set_section_settings",
            "section_id": "s_hero_cta",
            "settings": {
                "heading": "Eid sale — 20% off",
            },
        },
    ],
    "base_draft_updated_at": "2026-11-09T10:00:00.000Z",
}

response = requests.patch(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'operations' => [
        [
            'op' => 'set_section_settings',
            'section_id' => 's_hero_cta',
            'settings' => [
                'heading' => 'Eid sale — 20% off',
            ],
        ],
    ],
    'base_draft_updated_at' => '2026-11-09T10:00:00.000Z',
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/draft');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The operations were applied and the draft saved.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store. Popups and landing pages are not served here.
- `409` — The draft changed since `base_draft_updated_at` (`DRAFT_CONFLICT`; `error.fields.base_draft_updated_at` carries the current value — read the page again), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — An operation was refused (`error.fields['operations/<index>']` holds its code: `SECTION_NOT_FOUND`, `BLOCK_NOT_FOUND`, `GROUP_REQUIRED`, `GROUP_NOT_FOUND`, `AMBIGUOUS_POSITION`, `POSITION_OUT_OF_RANGE`, `DUPLICATE_ID`, `SHARED_SECTION`, `INVALID_OPERATION`), or the result breaks a tree rule (`error.fields` by JSON pointer) (`VALIDATION_ERROR`).
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "draft_updated_at": "2026-08-11T10:00:00.000Z",
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "summary": {}
}
```

## Publish a page

`POST /ext/v1/storefront/pages/{id}/publish` · Requires scope `storefront:publish`

Puts the page's draft live, in two calls. First call WITHOUT `confirmation_token`: nothing changes; the answer is a `preview` with a `summary` of what would go live and a single-use `confirmation_token` (10 minutes), or `no_changes` (no token). Show the summary to a person; then call again with the token AND an `Idempotency-Key` header to publish. If what was previewed changed in between, the confirm is refused (`409 PREVIEW_STALE`): preview again. A confirm uses its token up once it reaches the token check; a confirm refused earlier — for a missing `Idempotency-Key`, a 404/409 from the fence, or (menus) item validation — leaves it usable. The preview lists the sections added, removed, changed and moved against the live page; `first_publish` says the page has never been live (there is then nothing to roll back to). A draft that breaks a rule is refused before any token is made. A `message` sent with the preview is kept for the confirm unless the confirm sends its own. Company-scoped keys pass `store_id` in the body.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `confirmation_token` | `string` | No | Leave it out to get a preview and a token. Send the token from that preview (with an `Idempotency-Key` header) to confirm: it is single-use and lives 10 minutes. |
| `message` | `string` | No | The revision's note, shown in the page history. A preview's message is kept for its confirm unless the confirm sends its own. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/publish" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "message": "Eid banner and new arrivals"
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/publish");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "message": "Eid banner and new arrivals"
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "message": "Eid banner and new arrivals",
}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/publish",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'message' => 'Eid banner and new arrivals',
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/publish');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The preview, the publish, or `no_changes`.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store. Popups and landing pages are not served here.
- `409` — What was previewed changed before the confirm (`PREVIEW_STALE`: ask for a new preview), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — The draft breaks a rule (`error.fields` by JSON pointer, as for a draft save), the token is unknown, expired, not this key's or from another route's preview (`error.fields.confirmation_token = ['unknown_or_expired']`), or a token came without an `Idempotency-Key` header (`error.fields.idempotency_key = ['required_with_confirmation_token']`) (`VALIDATION_ERROR`).
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "status": "preview",
  "subject": "page:5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "summary": null,
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "confirmation_token": "a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8",
  "expires_at": "2026-08-11T10:00:00.000Z",
  "revision_id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "revision_version": 4,
  "published_at": "2026-08-11T10:00:00.000Z",
  "first_publish": false
}
```

## List page revisions

`GET /ext/v1/storefront/pages/{id}/revisions` · Requires scope `storefront:read`

A page's published revisions, newest first, marking the one shoppers see. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/revisions");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data } = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/revisions",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows = page["data"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/revisions');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
```

### Responses

- `200` — The revisions.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store. Popups and landing pages are not served here.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "data": [
    {
      "id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
      "version": 3,
      "message": "Spring banner",
      "created_at": "2026-08-11T10:00:00.000Z",
      "is_published": true
    }
  ]
}
```

## Roll a page back

`POST /ext/v1/storefront/pages/{id}/rollback` · Requires scope `storefront:publish`

Without `confirmation_token`: copies an earlier revision (from `GET /storefront/pages/{id}/revisions`) into the draft at once (`status: restored`); with `publish: true` the answer is also the preview of publishing it, with a token. Shoppers still see the live page. Confirm with that token, exactly as `POST …/publish`: First call WITHOUT `confirmation_token`: nothing changes; the answer is a `preview` with a `summary` of what would go live and a single-use `confirmation_token` (10 minutes), or `no_changes` (no token). Show the summary to a person; then call again with the token AND an `Idempotency-Key` header to publish. If what was previewed changed in between, the confirm is refused (`409 PREVIEW_STALE`): preview again. A confirm uses its token up once it reaches the token check; a confirm refused earlier — for a missing `Idempotency-Key`, a 404/409 from the fence, or (menus) item validation — leaves it usable. Company-scoped keys pass `store_id` in the body.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `confirmation_token` | `string` | No | Leave it out to get a preview and a token. Send the token from that preview (with an `Idempotency-Key` header) to confirm: it is single-use and lives 10 minutes. |
| `revision_id` | `uuid` | Yes | The revision to go back to, from `GET /storefront/pages/{id}/revisions`. |
| `publish` | `boolean` (default `false`) | No | Without a token: also preview publishing the restored draft (the answer then carries a token to confirm). With a token it is ignored: the confirm publishes the draft the preview showed. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/rollback" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "revision_id": "9c1e2f60-0d1c-4b3a-9a68-6f4d21f6a010",
  "publish": true
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/rollback");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "revision_id": "9c1e2f60-0d1c-4b3a-9a68-6f4d21f6a010",
    "publish": true
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "revision_id": "9c1e2f60-0d1c-4b3a-9a68-6f4d21f6a010",
    "publish": True,
}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/rollback",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'revision_id' => '9c1e2f60-0d1c-4b3a-9a68-6f4d21f6a010',
    'publish' => true,
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/rollback');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The restore (with its preview), or the publish.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store, or no such revision of it.
- `409` — What was previewed changed before the confirm (`PREVIEW_STALE`: ask for a new preview), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — The restored draft breaks a rule (`error.fields` by JSON pointer; the restore stands), the token is unknown, expired, not this key's or from another route's preview (`error.fields.confirmation_token = ['unknown_or_expired']`), or a token came without an `Idempotency-Key` header (`error.fields.idempotency_key = ['required_with_confirmation_token']`) (`VALIDATION_ERROR`).
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "status": "preview",
  "subject": "page:5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "summary": null,
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "confirmation_token": "a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8",
  "expires_at": "2026-08-11T10:00:00.000Z",
  "revision_id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "revision_version": 4,
  "published_at": "2026-08-11T10:00:00.000Z",
  "first_publish": false,
  "draft_updated_at": "2026-08-11T10:00:00.000Z"
}
```

## Validate a page tree

`POST /ext/v1/storefront/pages/{id}/validate` · Requires scope `storefront:read`

A dry run of a draft save: the tree is checked by the same rules a save through the API applies, and the result says whether the save would be accepted. Nothing is written. A read: it needs `storefront:read` and counts against the read rate limit. Company-scoped keys pass `store_id` in the body.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `uuid` | Yes | The page id, from `GET /storefront/pages` (find a page by `system_key` or `handle` there). |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `tree` | `object` | Yes | The page tree to check — the same shape `GET /storefront/pages/{id}` returns as `draft` (`{ sections: [...] }`, or `{ groups: {...} }` for the layout page). |
| `store_id` | `uuid` | No | The store, for a company-scoped key; on a store-scoped key it must match the key's own store. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/validate" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "tree": {
    "schema": 1,
    "sections": [
      {
        "id": "s_hero_cta",
        "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": []
      }
    ]
  }
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/validate");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "tree": {
      "schema": 1,
      "sections": [
        {
          "id": "s_hero_cta",
          "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": []
        }
      ]
    }
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "tree": {
        "schema": 1,
        "sections": [
            {
                "id": "s_hero_cta",
                "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": [],
            },
        ],
    },
}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/validate",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'tree' => [
        'schema' => 1,
        'sections' => [
            [
                'id' => 's_hero_cta',
                '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' => [],
            ],
        ],
    ],
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/pages/REPLACE_WITH_ID/validate');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The findings; `valid` is false when there are errors.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such page in the active theme of this store. Popups and landing pages are not served here.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "valid": false,
  "errors": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ]
}
```

## List the section catalogue

`GET /ext/v1/storefront/sections` · Requires scope `storefront:read`

Every section a page may hold: slug, name, category, a short description, the page context it needs (`contexts`), where it may be placed (`surfaces`), its latest version and whether it is deprecated. Filter by `category`, `page_type` or `search`; read a section's full settings schema with `GET /storefront/sections/{slug}`. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |
| `category` | `string` | No | Only sections of this registry category. |
| `page_type` | `string` | No | Only sections that may be placed on this kind of page: a section passes when it needs no page context, or the context this page provides (product, collection, cart, search). One of: `home`, `product`, `collection`, `cart`, `search`, `custom`, `layout`. |
| `search` | `string` | No | Case-insensitive substring of the slug, name or description. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/sections");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const { data } = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/sections",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

page = response.json()
rows = page["data"]
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/sections');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}

$rows = $response['data'];
```

### Responses

- `200` — The sections.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "data": [
    {
      "slug": "image_banner",
      "name": "Image banner",
      "category": "hero",
      "description": "A full-width image with a heading and a button.",
      "contexts": [],
      "surfaces": [
        "page",
        "landing"
      ],
      "latest_version": "2.1.0",
      "status": "active"
    }
  ]
}
```

## Get a section schema

`GET /ext/v1/storefront/sections/{slug}` · Requires scope `storefront:read`

One section's settings and blocks as JSON Schema (blocks with their `min`/`max`), its defaults, and the colour token names a `token:<name>` value may use. A deprecated section names its replacement when one is known. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `slug` | `string` | Yes | The section slug, from `GET /storefront/sections`. |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/sections/REPLACE_WITH_ID");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/sections/REPLACE_WITH_ID",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/sections/REPLACE_WITH_ID');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The section schema.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `404` — No such section (or it is not available to pages).
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "slug": "image_banner",
  "name": "Image banner",
  "category": "hero",
  "status": "active",
  "version": "2.1.0",
  "deprecated_replacement": null,
  "contexts": [],
  "surfaces": [
    "page",
    "landing"
  ],
  "schema": {},
  "defaults": {},
  "token_names": [
    "primary",
    "primary-500",
    "surface"
  ]
}
```

## Get the theme settings

`GET /ext/v1/storefront/theme-settings` · Requires scope `storefront:read`

The live design 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. Company-scoped keys must pass `store_id`: a design belongs to one store.

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Restrict the lookup to one store. Breadth control for company-scoped keys; on a store-scoped key it must match the key's own store. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

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

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/theme-settings");

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
  },
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

response = requests.get(
    "https://api.shopdeskbd.com/ext/v1/storefront/theme-settings",
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/theme-settings');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key],
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The theme settings.
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — The store has no active theme installation yet (`NO_ACTIVE_THEME`): install one in the dashboard first.
- `422` — Validation failed — `error.fields` maps each offending field to its messages.
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "live": {},
  "draft": null,
  "has_draft": false,
  "schema": {}
}
```

## Save the theme settings draft

`PUT /ext/v1/storefront/theme-settings/draft` · Requires scope `storefront:write`

Writes the design-token draft: `merge` (default) merges `settings` into the current draft, or into the live tokens when there is no draft; `replace` makes `settings` the whole draft. Values must follow the `schema` of `GET /storefront/theme-settings`. Shoppers see the live tokens until the draft is published. Company-scoped keys pass `store_id` in the body.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `settings` | `object` | Yes | Design tokens by group (`colors`, `fonts`, `radius`, `spacing`), in the forms `GET /storefront/theme-settings` lists under `schema`. |
| `mode` | `string` (default `merge`) | No | `merge` (default) merges `settings` into the current draft (or 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. One of: `merge`, `replace`. |

### Request

**cURL**

```bash
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: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{
  "settings": {
    "colors": {
      "primary": "#0f766e"
    },
    "radius": {
      "md": "10px"
    }
  },
  "mode": "merge"
}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/draft");

const response = await fetch(url, {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "settings": {
      "colors": {
        "primary": "#0f766e"
      },
      "radius": {
        "md": "10px"
      }
    },
    "mode": "merge"
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {
    "settings": {
        "colors": {
            "primary": "#0f766e",
        },
        "radius": {
            "md": "10px",
        },
    },
    "mode": "merge",
}

response = requests.put(
    "https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/draft",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode([
    'settings' => [
        'colors' => [
            'primary' => '#0f766e',
        ],
        'radius' => [
            'md' => '10px',
        ],
    ],
    'mode' => 'merge',
]);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/draft');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The draft now stored.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — A token is refused (`VALIDATION_ERROR`): `error.fields` is keyed by JSON pointer into `settings` (`/colors/primary`), each holding a code — `TOKEN_GROUP_UNKNOWN`, `TOKEN_FAMILY_UNKNOWN`, `TOKEN_VALUE_INVALID`, or `TOKEN_MISSING` (a `replace` without a live key).
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "draft": {},
  "has_draft": true,
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ]
}
```

## Publish the theme settings

`POST /ext/v1/storefront/theme-settings/publish` · Requires scope `storefront:publish`

Puts the design-token draft live for every page at once, in two calls. First call WITHOUT `confirmation_token`: nothing changes; the answer is a `preview` with a `summary` of what would go live and a single-use `confirmation_token` (10 minutes), or `no_changes` (no token). Show the summary to a person; then call again with the token AND an `Idempotency-Key` header to publish. If what was previewed changed in between, the confirm is refused (`409 PREVIEW_STALE`): preview again. A confirm uses its token up once it reaches the token check; a confirm refused earlier — for a missing `Idempotency-Key`, a 404/409 from the fence, or (menus) item validation — leaves it usable. The preview lists the changed tokens as JSON pointers (`/colors/primary`). No draft answers `no_changes`. Company-scoped keys pass `store_id` in the body.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | No | Optional, but honored: send it to make retries of this request safe. |

### Body parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `store_id` | `uuid` | No | Target store. REQUIRED with a company-scoped key; with a store-scoped key it may only repeat the key's own store. |
| `confirmation_token` | `string` | No | Leave it out to get a preview and a token. Send the token from that preview (with an `Idempotency-Key` header) to confirm: it is single-use and lives 10 minutes. |

### Request

**cURL**

```bash
export SHOPDESK_API_KEY="shopdesk_sk_YOUR_API_KEY"

curl -sS -X POST "https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/publish" \
  -H "Authorization: Bearer $SHOPDESK_API_KEY" \
  -H "Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**JavaScript**

```javascript
const url = new URL("https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/publish");

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SHOPDESK_API_KEY}`,
    "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({}),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message} [${error.request_id}]`);
}

const object = await response.json();
```

**Python**

```python
import os

import requests

payload = {}

response = requests.post(
    "https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/publish",
    json=payload,
    headers={
        "Authorization": f"Bearer {os.environ['SHOPDESK_API_KEY']}",
        "Idempotency-Key": "3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47",
    },
    timeout=30,
)

if not response.ok:
    error = response.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")

obj = response.json()
```

**PHP**

```php
<?php

$key = getenv('SHOPDESK_API_KEY');

$payload = json_encode((object) []);

$ch = curl_init('https://api.shopdeskbd.com/ext/v1/storefront/theme-settings/publish');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $key, 'Idempotency-Key: 3f2b8c1e-9d4a-4e7b-8a6f-2c5d1e0b9a47', 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_TIMEOUT => 30,
]);

$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$response = json_decode($body, true);

if ($status >= 400) {
    throw new RuntimeException("{$response['error']['code']}: {$response['error']['message']}");
}
```

### Responses

- `200` — The preview, the publish, or `no_changes`.
- `400` — An `Idempotency-Key` header was sent but is empty or longer than 255 characters (`VALIDATION_ERROR`; `error.fields` names the header).
- `401` — Missing/invalid API key, revoked or expired key, plan without API access, or a dead store.
- `403` — The key's scopes do not cover this endpoint.
- `409` — What was previewed changed before the confirm (`PREVIEW_STALE`: ask for a new preview), or the store has no active theme installation yet (`NO_ACTIVE_THEME`); or a request with this `Idempotency-Key` is still in flight (`IDEMPOTENCY_IN_FLIGHT`) — retry once it has finished.
- `422` — The confirm was refused: the token is unknown, expired, not this key's or from another route's preview (`error.fields.confirmation_token = ['unknown_or_expired']`), or a token came without an `Idempotency-Key` header (`error.fields.idempotency_key = ['required_with_confirmation_token']`) (`VALIDATION_ERROR`).
- `429` — Rate limit exceeded for this key. Honor `Retry-After` and the `X-RateLimit-*` headers.

**Example 200 response**

```json
{
  "status": "preview",
  "subject": "page:5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "summary": null,
  "warnings": [
    {
      "path": "/sections/0/settings/heading",
      "code": "REQUIRED",
      "message": "Heading is required"
    }
  ],
  "confirmation_token": "a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8a3f1c9e07b5d42e8",
  "expires_at": "2026-08-11T10:00:00.000Z",
  "revision_id": "5f7d2f60-0d1c-4b3a-9a68-6f4d21f6a001",
  "revision_version": 4,
  "published_at": "2026-08-11T10:00:00.000Z",
  "first_publish": false
}
```
