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

# POST /api/save-to-file — persist page edits to disk

> POST /api/save-to-file saves a Studio project state to the local JSON data files in src/data/. Called by the Studio editor when saving changes.

The `POST /api/save-to-file` endpoint persists Studio changes to the local JSON data files on disk. It accepts a `projectState` object — the full in-memory representation of edited content — and the `slug` of the page being saved, then writes the updated data to the appropriate file under `src/data/` (for example, `src/data/pages/about.json` for the About page).

The Studio editor calls this endpoint automatically when you save in the UI. You can also call it directly from scripts or custom tooling during local development.

<Warning>
  This endpoint is only available in **local development mode**. It writes directly to your project's source files on the local filesystem. In production, Studio routes saves through a different mechanism — this route will not be active.
</Warning>

## Request

* **Method:** `POST`
* **Path:** `/api/save-to-file`
* **Content-Type:** `application/json`

<ParamField body="projectState" type="object" required>
  The full project state object produced by the Studio editor. Contains all pages, collections, and site-level data in their edited form.
</ParamField>

<ParamField body="slug" type="string" required>
  The slug of the page or collection entry being saved — for example `"about"` or `"posts/write-the-readme-first"`. Used to determine which file on disk to write.
</ParamField>

```json theme={null}
{
  "slug": "about",
  "projectState": {
    "pages": {
      "about": {
        "id": "about-page",
        "slug": "about",
        "meta": {
          "title": "About Inkwell Journal and this collections demo",
          "description": "Inkwell Journal is a working OlonJS demo."
        },
        "sections": [
          {
            "$ref": "../site.json#/header"
          },
          {
            "id": "about-hero",
            "type": "page-hero",
            "data": {
              "label": "About",
              "title": "A journal that is also a diagram"
            },
            "settings": { "paddingTop": "xl" }
          },
          {
            "$ref": "../site.json#/footer"
          }
        ]
      }
    }
  }
}
```

```bash theme={null}
curl -X POST http://localhost:3000/api/save-to-file \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "about",
    "projectState": { "pages": { "about": { "id": "about-page", "slug": "about" } } }
  }'
```

## Response

**200 OK** — The data was written to disk successfully.

<ResponseField name="ok" type="boolean">
  Always `true` on a successful save.
</ResponseField>

```json theme={null}
{ "ok": true }
```

## Error responses

| Status | Meaning |
| - | - |
| `400` | `projectState` or `slug` is missing from the request body. Check that both fields are present and that `slug` is a non-empty string. |
| `500` | A filesystem write error occurred. The response body includes an `error` string with the underlying error message. |

```json theme={null}
{ "error": "ENOENT: no such file or directory, open 'src/data/pages/missing.json'" }
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.