Skip to content

Copy, rename and delete files and folders

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

This page has 4 commands: Copy file (POST /v2/files/copy), Rename file or folder (POST /v2/files/rename), Delete file or empty folder (POST /v2/files/delete) and Create new empty folder (POST /v2/files/mkdir). Each call needs a bearer token and counts towards your hourly API limit.

After reading this you will know

  • How to copy, rename and delete files and folders
  • Which parameters each of the 4 commands takes
  • Sample code in 9 languages and a sample answer

Every command on this page needs a bearer token and counts towards your hourly limit.

POSThttps://api.sirv.com/v2/files/copy

Use this API method to copy a single file.

Query parameters

NameTypeRequiredExampleDescription
fromstringYes/REST API Examples/aurora.jpgPath of the file to copy.
tostringYes/REST API Examples/aurora-copy.jpgPath of the copy, with its file name.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Response

HTTP 200 with an empty body when the command succeeds.

POSThttps://api.sirv.com/v2/files/rename

Use this API method to rename (or move) a file or folder.

Query parameters

NameTypeRequiredExampleDescription
fromstringYes/REST API Examples/uploaded.txtCurrent path of the file or folder.
tostringYes/REST API Examples/copies/uploaded-copy.txtNew path, with the new name.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Response

HTTP 200 with an empty body when the command succeeds.

POSThttps://api.sirv.com/v2/files/delete

Use this API method to delete a single file or an empty folder.

Query parameters

NameTypeRequiredExampleDescription
filenamestringYes/REST API Examples/aurora-copy.jpgPath of the file or empty folder to delete.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Response

HTTP 200 with an empty body when the command succeeds.

POSThttps://api.sirv.com/v2/files/mkdir

Use this API method to create a new empty folder.

Query parameters

NameTypeRequiredExampleDescription
dirnamestringYes/REST API Examples/copiesPath of the new folder, starting with /.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Example response

{
"name": "RiakFsError",
"message": "Path already exists: /REST API Examples/copies"
}
Back to top