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.

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
- Fetch
GET /api/files/file_idand preserve its parent ID. If an extension matters, include the desired extension explicitly in the new name. - Build the exact JSON body, for example
{"name":"Q4 forecast.pdf"}. Quotes and angle brackets are accepted; clients must still escape JSON correctly. - Send
PUT /api/files/file_id/renamewith bearer authorization andContent-Type: application/json. Keep this call separate from unrelated batch work. - 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. - Read the same file ID again and confirm
namechanged while the parent ID did not. Carry a returnedX-D1-Bookmarkfor D1-backed checks, without treating it as an ordering guarantee for workspace-object content. - 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.

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.
Related guides
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.