Move a file through the REST API safely
Move a file atomically with the REST API, handle scope, lock, and name conflicts, then verify its stable ID and parent with route-specific reads.
Last reviewed
PUT /api/files/:id/move changes a file’s parent without changing its ID or versions. Send folder_id as a destination folder ID, or null for the workspace root. Add name only when the same atomic request should also rename the file.

Before you start
- Use a full-access REST API key; read-only and upload-only keys cannot move files.
- Your workspace role must include
upload_files. A request that also suppliesnamerequiresrename_files. - Record the file ID, its current folder, and the destination folder. Pick a disposable file when testing automation.
- The destination must belong to the same workspace and must be visible to the caller.
Steps
- Read the file and destination first. Record the file ID, current parent, and exact destination ID before sending the mutation.
- Prepare JSON with the destination:
{"folder_id":"folder_destination"}. Use{"folder_id":null}for root, or add"name":"renamed.pdf"for a combined move and rename. - Send
PUT /api/files/file_id/movewithAuthorization: Bearer $DOSYA_API_KEYandContent-Type: application/json. Do not retry blindly after a lost response. - Require HTTP 200 and read
{ "ok": true, "name": "…" }. A 400 can mean the file is already in that folder, 403 covers permission or lock refusal, 404 hides an unavailable resource, and 409 reports a same-folder name conflict. - Send
GET /api/files/file_idand confirm the same ID reports the intendedfolder_idand optional new name. CarryX-D1-Bookmarkwhen the mutation returned one, but treat it only as ordering for D1-backed reads; file content metadata can come from the workspace repository. - List both the former and destination parents if downstream work depends on membership. Continue only when the old parent omits the ID and the destination contains it.

Expected result
The API returns 200 with ok: true; a route-specific metadata read shows the original file ID under the chosen parent. A combined rename exposes the supplied name in that verified result.
Troubleshooting
The request returns 409. Choose a different name, or resolve the existing item in the destination before retrying.
The request returns 403. Check upload_files, add rename_files for a combined rename, and inspect lock state. Changing API-key scope does not bypass a workspace role or lock.
The response was lost. Read the file before sending another mutation. The move route has no idempotency key; a verified destination means the first request already committed.
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.