> ## Documentation Index
> Fetch the complete documentation index at: https://docs.my-aichatbot.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Roll back

> Make an older version current again by copying it to the top of the history.

Rolling back never rewrites history. The chosen version's HTML is copied into a **new** version, which becomes current, so every `/v/{n}` URL keeps meaning what it always meant. Needs a key with **Pages write** turned on, and the Page must belong to the key's bot.

## Authorization

<ParamField header="Authorization" type="string" required>
  `Bearer mac_live_…`
</ParamField>

## Path parameters

<ParamField path="page_id" type="string" required>
  The Page's id.
</ParamField>

## Body

<ParamField body="to_version" type="integer" required>
  The kept version to copy.
</ParamField>

<ParamField body="change_note" type="string">
  Up to 500 characters, shown next to the new version in the app.
</ParamField>

## Response

<ResponseField name="ok" type="boolean">
  `true` on success.
</ResponseField>

<ResponseField name="version" type="integer">
  The new version number. If the chosen version is identical to the current one, nothing new is stored and this is the current number.
</ResponseField>

<ResponseField name="copied_from" type="integer">
  The version that was copied.
</ResponseField>

<ResponseField name="url" type="string">
  The Page's link.
</ResponseField>

<ResponseField name="version_url" type="string">
  The permanent `/v/{n}` address of the new version.
</ResponseField>

<RequestExample>
  ```bash curl theme={null}
  curl -X POST "https://app.my-aichatbot.com/api/v1/pages/$PAGE_ID/rollback" \
    -H "Authorization: Bearer $MAC_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "to_version": 3, "change_note": "Revert the broken chart" }'
  ```

  ```javascript Node.js theme={null}
  const res = await fetch(
    `https://app.my-aichatbot.com/api/v1/pages/${pageId}/rollback`,
    {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${process.env.MAC_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ to_version: 3, change_note: 'Revert the broken chart' })
    }
  )

  const { version, copied_from } = await res.json()
  ```

  ```python Python theme={null}
  import os, requests

  res = requests.post(
      f"https://app.my-aichatbot.com/api/v1/pages/{page_id}/rollback",
      headers={"Authorization": f"Bearer {os.environ['MAC_KEY']}"},
      json={"to_version": 3, "change_note": "Revert the broken chart"},
  )

  version = res.json()["version"]
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "ok": true,
    "version": 6,
    "copied_from": 3,
    "url": "https://app.my-aichatbot.com/pages/view/acme/sales-report",
    "version_url": "https://acme.my-aichatbot-space.com/sales-report/v/6"
  }
  ```

  ```json 404 No such version theme={null}
  {
    "ok": false,
    "error": { "code": "VERSION_NOT_FOUND", "message": "No such version." }
  }
  ```
</ResponseExample>

## Errors

| Status | Code                     | Meaning                                                                  |
| ------ | ------------------------ | ------------------------------------------------------------------------ |
| `401`  | `INVALID_API_KEY`        | Missing, broken, or revoked.                                             |
| `402`  | `STORAGE_QUOTA_EXCEEDED` | Workspace storage is full.                                               |
| `403`  | `PAGES_WRITE_DISABLED`   | Turn on **Pages write** for this key.                                    |
| `403`  | `FORBIDDEN_CHATBOT`      | The Page belongs to another bot.                                         |
| `403`  | `PAGE_DISABLED`          | The Page was disabled by an admin. Writes are rejected.                  |
| `404`  | `NOT_FOUND`              | No live Page with that id in this workspace.                             |
| `404`  | `VERSION_NOT_FOUND`      | That version was pruned, or never existed.                               |
| `413`  | `CONTENT_TOO_LARGE`      | The old version is bigger than your current plan's cap.                  |
| `422`  | `VALIDATION_FAILED`      | Bad body.                                                                |
| `429`  | `RATE_LIMITED`           | Over 120 writes per minute for this key. Wait for `retry_after_seconds`. |
| `500`  | `PERSIST_FAILED`         | We could not store the version. Safe to retry.                           |
