> This page is for version v1 (default).
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.butterix.com/llms.txt
> - v0: https://docs.butterix.com/v0/llms.txt

> For the MDX source of any page, append .mdx to the page URL.
> For a complete documentation index, see https://docs.butterix.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.butterix.com/_mcp/server.
> If something on this page is wrong or missing, POST JSON {"page": "<page URL>", "message": "<what is wrong>"} to https://docs.butterix.com/_biti/feedback/agent.

# 保存文件

`PUT /sites/{site}/editor/file`

把文件提交到草稿分支（一次保存 = 一次提交）。传入打开文件时的 `baseSha`，若文件已被他人修改，返回 409 与最新内容，便于合并。
已连接 Git 的站点不能直接写生产分支。

Base URL: https://api.butterix.com/v1

Authentication: bearer token in Authorization header or API key in cookie `biti_session`

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `site` | string | yes | 站点 slug 或 id |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `branch` | string | yes |  |
| `path` | string | yes |  |
| `content` | string | yes |  |
| `message` | string | no |  |
| `baseSha` | string | no |  |

## Example request

```bash
curl -X PUT https://api.butterix.com/v1/sites/acme-payments/editor/file \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
         "branch": "draft/3k9d2a1b-mf2x8k",
         "path": "pages/quickstart.mdx",
         "content": "string"
       }'
```

## Responses

### 200

新的 sha

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `sha` | string | no |  |

### 409

文件已被修改

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | no |  |
| `current` | object | no |  |
| `current.content` | string | no |  |
| `current.sha` | string | no |  |

### Example response (200)

```json
{
  "sha": "string"
}
```
