Rename a file through the REST API

Rename a file by ID with exact filename validation, preserve its parent and identity, and resolve lock, permission, or same-folder conflicts safely.

Last reviewed

PUT /api/files/:id/rename changes the stored name while keeping the file ID, parent, and version history. The extension is part of name; changing it can change how clients classify or preview the file.

Four workflow panels show reading the current file, building the validated name body, interpreting the rename receipt, and re-reading the same ID and parent.
The diagram covers reading the current file, building the validated name body, interpreting the rename receipt, and re-reading the same ID and parent. Open full-size screenshot.

Before you start

  • Use a full-access API key and a workspace role with rename_files.
  • Read the current file so you know its ID, parent, lock state, and existing name.
  • Choose a name of 1–255 characters after trimming. It cannot contain /, \, C0 control characters, or consist entirely of . or ...

Steps

  1. Fetch GET /api/files/file_id and preserve its parent ID. If an extension matters, include the desired extension explicitly in the new name.
  2. Build the exact JSON body, for example {"name":"Q4 forecast.pdf"}. Quotes and angle brackets are accepted; clients must still escape JSON correctly.
  3. Send PUT /api/files/file_id/rename with bearer authorization and Content-Type: application/json. Keep this call separate from unrelated batch work.
  4. Require HTTP 200 and { "ok": true, "name": "Q4 forecast.pdf" }. Treat 400 as invalid input, 403 as scope, role, or lock refusal, 404 as unavailable, and 409 as a sibling name collision.
  5. Read the same file ID again and confirm name changed while the parent ID did not. Carry a returned X-D1-Bookmark for D1-backed checks, without treating it as an ordering guarantee for workspace-object content.
  6. Open or download the renamed file when the extension changed. That check catches automation that accidentally changed the suffix even though the bytes remained intact.
Dosya developer overview with API and SDK entry points for rename a file through the rest api.
The developer overview supplies the API and SDK entry points referenced by “Rename a file through the REST API”. Open full-size screenshot.

Expected result

The success receipt echoes the normalized name. A fresh metadata read shows the same file ID and parent with the new name; its versions remain attached to that ID.

Troubleshooting

The server returns 400. Trim the value and check length, slash, backslash, control-character, . and .. rules.

The server returns 409. A sibling already uses the requested name. Choose another name or resolve that sibling before a new request.

The server returns 403. Confirm full key scope, rename_files, and that the file is not locked against the caller.

Was this helpful?

Loading helpfulness results…

Voting saves a necessary ballot cookie for up to 180 days so you can change your answer.

Questions and replies

Ask about the steps in this guide. Questions are reviewed before publication.

Keep account details, credentials and private files out of public questions. Use private support for those.

Loading questions…

    Sign in to your Dosya account to ask a question.

    Check the outcome before you retry

    Use these shared checks when a task needs a second look.