# Page API

> The HTML version is at https://showfold.page/docs.

A page hosted on Showfold can ask about its own owner: the pages on their home page and how the visitor is related to the owner. It can also save a signed-in visitor’s own data in the owner’s stores. Paste in a snippet or an agent prompt, or call the API from the page’s own script.

## How calls work

Each call is a GET from the page’s own script to a path on its own address, starting with /_showfold/api/v1/; saving a record is a POST to the same kind of path. Showfold knows which page is asking from the address it runs on, so a call names no page, owner or key. The same page served anywhere else gets no answer.

Each answer holds only what the visitor could already see, and nothing in it says who the visitor is.

## Pages

`GET /_showfold/api/v1/pages`

The owner’s pages shown on their home page, in the home page’s order, 50 at a time.

### Query

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `tag` | string | Optional | Only pages with this tag. |
| `after` | string | Optional | The next value from the previous answer, for the next 50 pages. |

### Answers

| Name | Type | Description |
| --- | --- | --- |
| `pages` | array | One entry per page, in the home page’s order. |
| `pages[].title` | string | The page’s title. |
| `pages[].icon` | string or null | The address of the page’s icon, or null. |
| `pages[].address` | string | The page’s own address. |
| `pages[].locked` | boolean | True when the visitor can’t open the page yet. |
| `next` | string or null | Pass as after for the next 50 pages. Null on the last batch. |

### Error answers

| Status | Error | Description |
| --- | --- | --- |
| `404` | no body | This page can’t ask right now. The answer has no body and never says why. |
| `429` | `try again later` | Too many calls in a short time. Retry-After says how many seconds to wait. |

### Plans

Every plan

### Request

```js
fetch("/_showfold/api/v1/pages?tag=reports")
  .then((r) => r.json())
```

### Example response

```json
{
  "pages": [
    {
      "title": "Chapter 12",
      "icon": null,
      "address": "https://<owner>.showfold.page/i/<page id>",
      "locked": false
    }
  ],
  "next": null
}
```

## Viewer

`GET /_showfold/api/v1/viewer`

How the visitor is related to the page’s owner. Nothing in the answer says who the visitor is.

### Query

Nothing. The answer is about the page it’s called from.

### Answers

| Name | Type | Description |
| --- | --- | --- |
| `relationship` | string | One of owner, member, guest or none. owner is the workspace’s owning account. member is a member of the workspace’s organization. guest is a visitor on the owner’s guest list; guest needs Pro or Team — on Free there is no guest list and a guest is answered as none. none means the visitor is not signed in to this owner, or has not yet pressed Continue or Join on this owner’s pages. |

### Error answers

| Status | Error | Description |
| --- | --- | --- |
| `404` | no body | This page can’t ask right now. The answer has no body and never says why. |
| `429` | `try again later` | Too many calls in a short time. Retry-After says how many seconds to wait. |

### Plans

Every plan

### Request

```js
fetch("/_showfold/api/v1/viewer")
  .then((r) => r.json())
```

### Example response

```json
{
  "relationship": "guest"
}
```

## Widget

`GET /_showfold/api/v1/widget/<join, guest-badge, sign-in or data-panel>`

An address for Showfold’s own Join button, guest badge, Sign in button or Data on this page button, good for one minute, to load in a frame on this page. The Join button, guest badge, Sign in and Data on this page snippets do this for you.

### Query

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `kind` | string | Required | In the path: join for the Join button, guest-badge for the guest badge, sign-in for the Sign in button, data-panel for the Data on this page button. |

### Answers

| Name | Type | Description |
| --- | --- | --- |
| `url` | string | The frame’s address, good for one minute. |
| `expiresAt` | string | When the address stops working, as an ISO 8601 time. |

### Error answers

| Status | Error | Description |
| --- | --- | --- |
| `404` | no body | This page can’t ask right now. The answer has no body and never says why. |
| `429` | `try again later` | Too many calls in a short time. Retry-After says how many seconds to wait. |

### Plans

Every plan

### Request

```js
fetch("/_showfold/api/v1/widget/join")
  .then((r) => r.json())
```

### Example response

```json
{
  "url": "https://static.showfold.page/i/page-button?t=…",
  "expiresAt": "2026-10-27T12:01:00.000Z"
}
```

## Store

`GET, POST /_showfold/api/v1/store/<global or page>/<store name>`

Read or save the signed-in visitor’s own record in one of the owner’s stores. Only the visitor sees it, unless the store is owner-visible.

### Query

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `scope` | string | Required | In the path: global for a store shared by all the owner’s pages, or page for this page’s own store. |
| `name` | string | Required | In the path: the store’s name. |

### Answers

| Name | Type | Description |
| --- | --- | --- |
| `record` | object or null | The visitor’s record, or null before their first save. |
| `version` | integer | The record’s version, 0 before the first save. |

### Body

| Name | Type | Description |
| --- | --- | --- |
| `record` | object | The whole record, as JSON. In a write-once store it is laid over the saved record. |
| `expectVersion` | integer | Optional. The version you loaded, so a save from an out-of-date device is refused instead of overwriting newer progress. Leave it out and the last save wins. |

### Save answers

| Name | Type | Description |
| --- | --- | --- |
| `version` | integer | The record’s new version. |

### Error answers

| Status | Error | Description |
| --- | --- | --- |
| `401` | `sign in needed` | The visitor is signed out. Show the Sign in snippet. |
| `403` | `notice needed` | The store is owner-visible or write-once and the visitor has not agreed to Showfold’s current notice. Ask Showfold’s frame to show it, then save again. Nothing is saved. |
| `404` | no body | This page can’t ask right now. The answer has no body and never says why. |
| `404` | `not available` | There is no such store, or the owner’s stores are not available. |
| `409` | `out of date` | The save’s expectVersion is older than the saved record. The answer holds the newer version. |
| `409` | `already saved` | The store is write-once and the save would change a value already saved. The answer names the field, never a value. Nothing is saved. |
| `422` | `invalid` | The record doesn’t fit the store. The answer names the field (missing, unknown or wrong type) or the size limit, never a value. |
| `429` | `try again later` | Too many calls in a short time. Retry-After says how many seconds to wait. |

### Plans

Pro and Team

On Free there are no stores, so the call answers 404 not available. [Upgrade](https://showfold.page/pricing)

### Request

```js
fetch("/_showfold/api/v1/store/global/theme")
  .then((r) => r.json())
```

### Example response

```json
{
  "record": {
    "dark": true
  },
  "version": 4
}
```

### Save request

```js
fetch("/_showfold/api/v1/store/global/theme", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ record: { dark: true }, expectVersion: 4 }),
})
  .then((r) => r.json())
```

### Example save response

```json
{
  "version": 5
}
```

## Join button

Shows Showfold’s own Join button. Guests see You’re a guest ✓ in its place, and the owner and members see You have access ✓. It shows nothing when the owner has no guest list.

### Where to paste it

Paste it into your page’s HTML where the button should appear.

### Plans

Pro and Team

On Free there’s no guest list, so the button draws nothing. [Upgrade](https://showfold.page/pricing)

### HTML

```html
<div data-showfold="join"></div>
<script>(function () {
  var TYPE = "showfold:frame-size";
  var MAX_WIDTH = 320;
  var MAX_HEIGHT = 64;
  var CALL = "/_showfold/api/v1/widget/";
  var TITLES = { "join": "Join on Showfold", "guest-badge": "Showfold guest badge", "sign-in": "Sign in on Showfold", "data-panel": "Data on this page on Showfold" };
  function clamp(value, max) {
    return Math.max(0, Math.min(max, value));
  }
  function place(element, kind, address) {
    var origin = new URL(address).origin;
    var frame = document.createElement("iframe");
    frame.src = address;
    frame.title = TITLES[kind];
    frame.setAttribute("scrolling", "no");
    frame.setAttribute("style", "border:0;width:0;height:0");
    window.addEventListener("message", function (event) {
      var data = event.data;
      if (event.origin !== origin || event.source !== frame.contentWindow) return;
      if (!data || data.type !== TYPE) return;
      if (typeof data.width !== "number" || typeof data.height !== "number") return;
      if (!isFinite(data.width) || !isFinite(data.height)) return;
      frame.style.width = clamp(data.width, MAX_WIDTH) + "px";
      frame.style.height = clamp(data.height, MAX_HEIGHT) + "px";
    });
    element.appendChild(frame);
  }
  function mount(element) {
    var kind = element.getAttribute("data-showfold");
    element.setAttribute("data-showfold-ready", "");
    try {
      fetch(CALL + kind, { credentials: "same-origin", cache: "no-store" })
        .then(function (response) {
          return response.status === 200 ? response.json() : null;
        })
        .then(function (body) {
          if (body && typeof body.url === "string") place(element, kind, body.url);
        })
        .catch(function () {});
    } catch (error) {}
  }
  var elements = document.querySelectorAll('[data-showfold="join"],[data-showfold="guest-badge"],[data-showfold="sign-in"],[data-showfold="data-panel"]');
  for (var i = 0; i < elements.length; i++) {
    if (!elements[i].hasAttribute("data-showfold-ready")) mount(elements[i]);
  }
})();</script>
```

## Guest badge

Shows You’re a guest ✓ to the owner’s guests, and nothing to anyone else.

### Where to paste it

Paste it into your page’s HTML where the badge should appear, such as beside the page’s title.

### Plans

Pro and Team

On Free there’s no guest list, so the badge draws nothing. [Upgrade](https://showfold.page/pricing)

### HTML

```html
<div data-showfold="guest-badge"></div>
<script>(function () {
  var TYPE = "showfold:frame-size";
  var MAX_WIDTH = 320;
  var MAX_HEIGHT = 64;
  var CALL = "/_showfold/api/v1/widget/";
  var TITLES = { "join": "Join on Showfold", "guest-badge": "Showfold guest badge", "sign-in": "Sign in on Showfold", "data-panel": "Data on this page on Showfold" };
  function clamp(value, max) {
    return Math.max(0, Math.min(max, value));
  }
  function place(element, kind, address) {
    var origin = new URL(address).origin;
    var frame = document.createElement("iframe");
    frame.src = address;
    frame.title = TITLES[kind];
    frame.setAttribute("scrolling", "no");
    frame.setAttribute("style", "border:0;width:0;height:0");
    window.addEventListener("message", function (event) {
      var data = event.data;
      if (event.origin !== origin || event.source !== frame.contentWindow) return;
      if (!data || data.type !== TYPE) return;
      if (typeof data.width !== "number" || typeof data.height !== "number") return;
      if (!isFinite(data.width) || !isFinite(data.height)) return;
      frame.style.width = clamp(data.width, MAX_WIDTH) + "px";
      frame.style.height = clamp(data.height, MAX_HEIGHT) + "px";
    });
    element.appendChild(frame);
  }
  function mount(element) {
    var kind = element.getAttribute("data-showfold");
    element.setAttribute("data-showfold-ready", "");
    try {
      fetch(CALL + kind, { credentials: "same-origin", cache: "no-store" })
        .then(function (response) {
          return response.status === 200 ? response.json() : null;
        })
        .then(function (body) {
          if (body && typeof body.url === "string") place(element, kind, body.url);
        })
        .catch(function () {});
    } catch (error) {}
  }
  var elements = document.querySelectorAll('[data-showfold="join"],[data-showfold="guest-badge"],[data-showfold="sign-in"],[data-showfold="data-panel"]');
  for (var i = 0; i < elements.length; i++) {
    if (!elements[i].hasAttribute("data-showfold-ready")) mount(elements[i]);
  }
})();</script>
```

## Page list

Lists the owner’s pages shown on their home page as plain links, with a lock on locked pages, styled by your page. Set data-tag to list one tag. Set data-render to none to get the pages as data in a showfold:pages event and draw them yourself.

### Where to paste it

Paste it into your page’s HTML where the list should appear. Leave data-tag empty to list every page on your home page. Its markup uses the class names showfold-pages, showfold-page, showfold-page-link, showfold-page-icon, showfold-lock and showfold-more.

### Plans

Every plan

### HTML

```html
<div data-showfold="pages" data-tag=""></div>
<script>(function () {
  function load(tag, after) {
    var query = "";
    if (tag) query += "?tag=" + encodeURIComponent(tag);
    if (after) query += (tag ? "&" : "?") + "after=" + encodeURIComponent(after);
    try {
      return fetch("/_showfold/api/v1/pages" + query, { credentials: "same-origin", cache: "no-store" })
        .then(function (response) {
          return response.status === 200 ? response.json() : null;
        })
        .then(function (body) {
          if (!body || !Array.isArray(body.pages)) return null;
          return { pages: body.pages, next: typeof body.next === "string" ? body.next : null };
        })
        .catch(function () {
          return null;
        });
    } catch (error) {
      return Promise.resolve(null);
    }
  }
  function row(page) {
    var item = document.createElement("li");
    item.className = "showfold-page";
    var link = document.createElement("a");
    link.className = "showfold-page-link";
    link.setAttribute("href", page.address);
    link.setAttribute("target", "_top");
    if (page.icon) {
      var icon = document.createElement("img");
      icon.className = "showfold-page-icon";
      icon.setAttribute("src", page.icon);
      icon.setAttribute("alt", "");
      link.appendChild(icon);
    }
    link.appendChild(document.createTextNode(page.title));
    item.appendChild(link);
    if (page.locked) {
      var lock = document.createElement("span");
      lock.className = "showfold-lock";
      lock.setAttribute("role", "img");
      lock.setAttribute("aria-label", "Locked");
      lock.textContent = "🔒";
      item.appendChild(lock);
    }
    return item;
  }
  function drawn(element, tag) {
    var list = null;
    var button = null;
    function show(after) {
      load(tag, after).then(function (batch) {
        if (!batch) {
          if (button) button.disabled = false;
          return;
        }
        if (button) {
          element.removeChild(button);
          button = null;
        }
        if (batch.pages.length === 0 && !list) return;
        if (!list) {
          list = document.createElement("ul");
          list.className = "showfold-pages";
          element.appendChild(list);
        }
        for (var i = 0; i < batch.pages.length; i++) list.appendChild(row(batch.pages[i]));
        if (batch.next) {
          var next = batch.next;
          button = document.createElement("button");
          button.type = "button";
          button.className = "showfold-more";
          button.textContent = "Show more";
          button.addEventListener("click", function () {
            button.disabled = true;
            show(next);
          });
          element.appendChild(button);
        }
      });
    }
    show(null);
  }
  function data(element, tag) {
    function run(after) {
      load(tag, after).then(function (batch) {
        if (!batch) return;
        var more = batch.next
          ? function () {
              run(batch.next);
            }
          : null;
        element.dispatchEvent(
          new CustomEvent("showfold:pages", { bubbles: true, detail: { pages: batch.pages, more: more } })
        );
      });
    }
    run(null);
  }
  var elements = document.querySelectorAll('[data-showfold="pages"]');
  for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    if (element.hasAttribute("data-showfold-ready")) continue;
    element.setAttribute("data-showfold-ready", "");
    var tag = element.getAttribute("data-tag") || "";
    if (element.getAttribute("data-render") === "none") data(element, tag);
    else drawn(element, tag);
  }
})();</script>
```

## Sign in

Shows Showfold’s own Sign in button while the visitor is signed out, so they can sign in on Showfold and come back to save. It shows nothing once they are signed in, or when the owner’s stores are not available.

### Where to paste it

Paste it into your page’s HTML next to the control that saves.

### Plans

Pro and Team

On Free there are no stores, so the button draws nothing. [Upgrade](https://showfold.page/pricing)

### HTML

```html
<div data-showfold="sign-in"></div>
<script>(function () {
  var TYPE = "showfold:frame-size";
  var MAX_WIDTH = 320;
  var MAX_HEIGHT = 64;
  var CALL = "/_showfold/api/v1/widget/";
  var TITLES = { "join": "Join on Showfold", "guest-badge": "Showfold guest badge", "sign-in": "Sign in on Showfold", "data-panel": "Data on this page on Showfold" };
  function clamp(value, max) {
    return Math.max(0, Math.min(max, value));
  }
  function place(element, kind, address) {
    var origin = new URL(address).origin;
    var frame = document.createElement("iframe");
    frame.src = address;
    frame.title = TITLES[kind];
    frame.setAttribute("scrolling", "no");
    frame.setAttribute("style", "border:0;width:0;height:0");
    window.addEventListener("message", function (event) {
      var data = event.data;
      if (event.origin !== origin || event.source !== frame.contentWindow) return;
      if (!data || data.type !== TYPE) return;
      if (typeof data.width !== "number" || typeof data.height !== "number") return;
      if (!isFinite(data.width) || !isFinite(data.height)) return;
      frame.style.width = clamp(data.width, MAX_WIDTH) + "px";
      frame.style.height = clamp(data.height, MAX_HEIGHT) + "px";
    });
    element.appendChild(frame);
  }
  function mount(element) {
    var kind = element.getAttribute("data-showfold");
    element.setAttribute("data-showfold-ready", "");
    try {
      fetch(CALL + kind, { credentials: "same-origin", cache: "no-store" })
        .then(function (response) {
          return response.status === 200 ? response.json() : null;
        })
        .then(function (body) {
          if (body && typeof body.url === "string") place(element, kind, body.url);
        })
        .catch(function () {});
    } catch (error) {}
  }
  var elements = document.querySelectorAll('[data-showfold="join"],[data-showfold="guest-badge"],[data-showfold="sign-in"],[data-showfold="data-panel"]');
  for (var i = 0; i < elements.length; i++) {
    if (!elements[i].hasAttribute("data-showfold-ready")) mount(elements[i]);
  }
})();</script>
```

## Data on this page

Shows Showfold’s own Data on this page button. It opens Showfold’s panel, where a visitor sees what this page can keep for them, who can see it, and where to view, download or erase it. It shows nothing when the owner’s stores are not available.

### Where to paste it

Paste it into your page’s HTML where visitors look for privacy or account links, such as the footer.

### Plans

Pro and Team

On Free there are no stores, so the button draws nothing. [Upgrade](https://showfold.page/pricing)

### HTML

```html
<div data-showfold="data-panel"></div>
<script>(function () {
  var TYPE = "showfold:frame-size";
  var MAX_WIDTH = 320;
  var MAX_HEIGHT = 64;
  var CALL = "/_showfold/api/v1/widget/";
  var TITLES = { "join": "Join on Showfold", "guest-badge": "Showfold guest badge", "sign-in": "Sign in on Showfold", "data-panel": "Data on this page on Showfold" };
  function clamp(value, max) {
    return Math.max(0, Math.min(max, value));
  }
  function place(element, kind, address) {
    var origin = new URL(address).origin;
    var frame = document.createElement("iframe");
    frame.src = address;
    frame.title = TITLES[kind];
    frame.setAttribute("scrolling", "no");
    frame.setAttribute("style", "border:0;width:0;height:0");
    window.addEventListener("message", function (event) {
      var data = event.data;
      if (event.origin !== origin || event.source !== frame.contentWindow) return;
      if (!data || data.type !== TYPE) return;
      if (typeof data.width !== "number" || typeof data.height !== "number") return;
      if (!isFinite(data.width) || !isFinite(data.height)) return;
      frame.style.width = clamp(data.width, MAX_WIDTH) + "px";
      frame.style.height = clamp(data.height, MAX_HEIGHT) + "px";
    });
    element.appendChild(frame);
  }
  function mount(element) {
    var kind = element.getAttribute("data-showfold");
    element.setAttribute("data-showfold-ready", "");
    try {
      fetch(CALL + kind, { credentials: "same-origin", cache: "no-store" })
        .then(function (response) {
          return response.status === 200 ? response.json() : null;
        })
        .then(function (body) {
          if (body && typeof body.url === "string") place(element, kind, body.url);
        })
        .catch(function () {});
    } catch (error) {}
  }
  var elements = document.querySelectorAll('[data-showfold="join"],[data-showfold="guest-badge"],[data-showfold="sign-in"],[data-showfold="data-panel"]');
  for (var i = 0; i < elements.length; i++) {
    if (!elements[i].hasAttribute("data-showfold-ready")) mount(elements[i]);
  }
})();</script>
```

## Dark mode that follows the reader

Has your agent add a dark-mode switch to your pages that remembers each signed-in reader’s choice on every page and device.

### Where to paste it

Paste it into your agent. If Showfold asks you to confirm the store first, your agent gives you the link and waits.

### Plans

Pro and Team

On Free there are no stores, so your agent can’t create one. [Upgrade](https://showfold.page/pricing)

### Prompt

```text
On my Showfold pages, add a dark-mode switch that remembers each reader’s choice across all my pages.
1. Use create_store to create a global store named theme with one optional bool field named dark. Create nothing else.
2. If create_store answers with a confirm link, give me the link and stop until I tell you I have confirmed it. Never ask again to get around it.
3. On each page I name, add a switch that reads GET /_showfold/api/v1/store/global/theme when the page loads and turns dark mode on when dark is true, and that saves the reader’s choice with POST /_showfold/api/v1/store/global/theme and the body {"record":{"dark":true}} or {"record":{"dark":false}}.
4. Paste Showfold’s Sign in snippet unchanged next to the switch. It shows only while the reader is signed out; while a read or save answers 401, hide the switch.
5. Upload each page as a new version.
```

## Save progress on one page

Has your agent save each signed-in visitor’s progress on one page, such as a game save, so it follows them to any device.

### Where to paste it

Paste it into your agent. If Showfold asks you to confirm the store first, your agent gives you the link and waits.

### Plans

Pro and Team

On Free there are no stores, so your agent can’t create one. [Upgrade](https://showfold.page/pricing)

### Prompt

```text
On my Showfold page <name the page>, save each signed-in visitor’s progress on Showfold instead of in the browser.
1. Read the page’s code and list what progress it keeps.
2. Use create_store to create a page store named save on that page, with one typed field for each piece of progress (string, number, int, bool, list or object), every field optional. Create nothing else.
3. If create_store answers with a confirm link, give me the link and stop until I tell you I have confirmed it. Never ask again to get around it.
4. When the page loads, read GET /_showfold/api/v1/store/page/save. To save, POST /_showfold/api/v1/store/page/save with {"record":{…},"expectVersion":<the version from the last read or save>}.
5. On 409, load the newer save instead of overwriting it. On 422, keep going and tell the visitor the save failed. Paste Showfold’s Sign in snippet unchanged where the save status shows; it appears only while the visitor is signed out.
6. Upload the page as a new version.
```
