---
title: "Autosave / rename / move / archive / restore a file"
method: PATCH
path: "/api/v1/files/{id}"
tags: ["workspace"]
---

# Autosave / rename / move / archive / restore a file

`PATCH /api/v1/files/{id}`

## Request

- Base URL: `https://mdtidy.com`
- URL: `https://mdtidy.com/api/v1/files/{id}`
- Auth: HTTP bearer

Content writes require an optimistic-lock precondition: send `version` in the request body (recommended). The `If-Match: "<version>"` header is also accepted, but callers behind a CDN should prefer `version` — `If-Match` is a reserved HTTP conditional header (RFC 9110 §13.1.1) that an intermediary may evaluate at the edge and answer with 412 even when the write succeeds. The origin itself never returns 412. A stale precondition returns 409 with the current server copy. Content writes overwrite the working blob and bump the version; they do not create version-history rows. 0 credits.

## Headers

- `If-Match` string

## Request body

- UpdateFileRequest: Autosave / rename / move / archive. Content writes require an optimistic-lock precondition — the `version` field (recommended) or the `If-Match` header — and bump the file version.
  - `content` string
  - `name` string
  - `folder_id` string, uuid, nullable
  - `archived` boolean
  - `version` integer: Optimistic-lock precondition for content writes; recommended over the If-Match header (which a CDN may 412 at the edge).

## Response `200`

Updated file.

- File
  - `id` string, uuid, required
  - `type` 'file', required
  - `project_id` string, uuid, required
  - `folder_id` string, uuid, nullable, required
  - `folder_path` object[]: Top-down folder ancestry (excludes project + file); [] at the project root. Returned by GET /v1/files/{id} and POST /v1/files.
    - `id` string, uuid, required
    - `name` string, required
  - `name` string, required
  - `archived` boolean, required
  - `version` integer, required
  - `etag` string, required: Quoted version; mirrors the ETag header.
  - `last_opened_at` string, nullable, required
  - `created_at` string, required
  - `updated_at` string, required
  - `credits_remaining` integer
  - `content` string: Markdown body; returned by GET /v1/files/{id}.
  - `after_md_gcs` string, nullable
  - `rendered_html_gcs` string, nullable

## Other responses

- `401`: X-API-KEY is malformed, unknown, or revoked.
- `404`: Resource not found, or not owned by the caller (IDOR-safe).
- `409`: Name collision, stale write, or a resource limit was reached.
- `412`: Edge-injected: a CDN evaluated the `If-Match` request header and rejected it (the origin never returns 412, and the write may have already committed). Use the `version` body field instead.
- `413`: Request body exceeds the 1 MB cap.
- `422`: Request body failed validation.
- `428`: A content write omitted the required If-Match / version precondition.
- `429`: Per-key rate limit (60/min) exceeded.

---

[API](https://skmtc.dev/mdtidy/apis/markdown-tidy-api.md) · [All operations](https://skmtc.dev/mdtidy/apis/markdown-tidy-api/llms.txt) · [OpenAPI document](https://skmtc.dev/mdtidy/apis/markdown-tidy-api/revisions/caeec6fad155?raw)
