# Copy, rename and delete files and folders

Every command on this page needs a [bearer token](/help/rest-api/reference/authentication/) and counts towards your [hourly limit](/help/rest-api/reference/rate-limits-and-errors/).

## Copy file

**POST**`https://api.sirv.com/v2/files/copy`

Use this API method to copy a single file.

Query parameters

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `from` | string | Yes | `/REST API Examples/aurora.jpg` | Path of the file to copy. |
| `to` | string | Yes | `/REST API Examples/aurora-copy.jpg` | Path of the copy, with its file name. |

Example request

-   [Node.js](#tab-panel-0-0)
-   [Python](#tab-panel-0-1)
-   [cURL](#tab-panel-0-2)
-   [Java](#tab-panel-0-3)
-   [C#](#tab-panel-0-4)
-   [PHP](#tab-panel-0-5)
-   [Go](#tab-panel-0-6)
-   [Ruby](#tab-panel-0-7)
-   [Swift](#tab-panel-0-8)

```js
// 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());
```

```python
import requests

res = requests.post(
    'https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg',
    headers={'authorization': 'Bearer BEARER_TOKEN'},
)
print(res.status_code, res.text)
```

```bash
curl --request POST \
  --url 'https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg' \
  --header 'authorization: Bearer BEARER_TOKEN'
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg"))
    .header("authorization", "Bearer BEARER_TOKEN")
    .method("POST", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
```

```csharp
using System.Net.Http.Headers;

using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```php
<?php
$ch = curl_init('https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg');
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'],
  CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
```

```go
package main

import (
  "fmt"
  "io"
  "net/http"
)

func main() {
  req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg", nil)
  req.Header.Set("authorization", "Bearer BEARER_TOKEN")
  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()
  out, _ := io.ReadAll(res.Body)
  fmt.Println(res.Status, string(out))
}
```

```ruby
require 'net/http'

uri = URI('https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg')
req = Net::HTTP::Post.new(uri)
req['authorization'] = 'Bearer BEARER_TOKEN'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, res.body
```

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/copy?from=%2FREST%20API%20Examples%2Faurora.jpg&to=%2FREST%20API%20Examples%2Faurora-copy.jpg")!)
request.httpMethod = "POST"
request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")
let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))
```

Response

HTTP 200 with an empty body when the command succeeds.

## Rename file or folder

**POST**`https://api.sirv.com/v2/files/rename`

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

Query parameters

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `from` | string | Yes | `/REST API Examples/uploaded.txt` | Current path of the file or folder. |
| `to` | string | Yes | `/REST API Examples/copies/uploaded-copy.txt` | New path, with the new name. |

Example request

-   [Node.js](#tab-panel-1-0)
-   [Python](#tab-panel-1-1)
-   [cURL](#tab-panel-1-2)
-   [Java](#tab-panel-1-3)
-   [C#](#tab-panel-1-4)
-   [PHP](#tab-panel-1-5)
-   [Go](#tab-panel-1-6)
-   [Ruby](#tab-panel-1-7)
-   [Swift](#tab-panel-1-8)

```js
// 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());
```

```python
import requests

res = requests.post(
    'https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt',
    headers={'authorization': 'Bearer BEARER_TOKEN'},
)
print(res.status_code, res.text)
```

```bash
curl --request POST \
  --url 'https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt' \
  --header 'authorization: Bearer BEARER_TOKEN'
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt"))
    .header("authorization", "Bearer BEARER_TOKEN")
    .method("POST", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
```

```csharp
using System.Net.Http.Headers;

using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```php
<?php
$ch = curl_init('https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt');
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'],
  CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
```

```go
package main

import (
  "fmt"
  "io"
  "net/http"
)

func main() {
  req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt", nil)
  req.Header.Set("authorization", "Bearer BEARER_TOKEN")
  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()
  out, _ := io.ReadAll(res.Body)
  fmt.Println(res.Status, string(out))
}
```

```ruby
require 'net/http'

uri = URI('https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt')
req = Net::HTTP::Post.new(uri)
req['authorization'] = 'Bearer BEARER_TOKEN'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, res.body
```

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/rename?from=%2FREST%20API%20Examples%2Fuploaded.txt&to=%2FREST%20API%20Examples%2Fcopies%2Fuploaded-copy.txt")!)
request.httpMethod = "POST"
request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")
let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))
```

Response

HTTP 200 with an empty body when the command succeeds.

## Delete file or empty folder

**POST**`https://api.sirv.com/v2/files/delete`

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

Query parameters

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `filename` | string | Yes | `/REST API Examples/aurora-copy.jpg` | Path of the file or empty folder to delete. |

Example request

-   [Node.js](#tab-panel-2-0)
-   [Python](#tab-panel-2-1)
-   [cURL](#tab-panel-2-2)
-   [Java](#tab-panel-2-3)
-   [C#](#tab-panel-2-4)
-   [PHP](#tab-panel-2-5)
-   [Go](#tab-panel-2-6)
-   [Ruby](#tab-panel-2-7)
-   [Swift](#tab-panel-2-8)

```js
// 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());
```

```python
import requests

res = requests.post(
    'https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg',
    headers={'authorization': 'Bearer BEARER_TOKEN'},
)
print(res.status_code, res.text)
```

```bash
curl --request POST \
  --url 'https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg' \
  --header 'authorization: Bearer BEARER_TOKEN'
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg"))
    .header("authorization", "Bearer BEARER_TOKEN")
    .method("POST", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
```

```csharp
using System.Net.Http.Headers;

using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```php
<?php
$ch = curl_init('https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg');
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'],
  CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
```

```go
package main

import (
  "fmt"
  "io"
  "net/http"
)

func main() {
  req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg", nil)
  req.Header.Set("authorization", "Bearer BEARER_TOKEN")
  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()
  out, _ := io.ReadAll(res.Body)
  fmt.Println(res.Status, string(out))
}
```

```ruby
require 'net/http'

uri = URI('https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg')
req = Net::HTTP::Post.new(uri)
req['authorization'] = 'Bearer BEARER_TOKEN'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, res.body
```

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg")!)
request.httpMethod = "POST"
request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")
let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))
```

Response

HTTP 200 with an empty body when the command succeeds.

## Create new empty folder

**POST**`https://api.sirv.com/v2/files/mkdir`

Use this API method to create a new empty folder.

Query parameters

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `dirname` | string | Yes | `/REST API Examples/copies` | Path of the new folder, starting with /. |

Example request

-   [Node.js](#tab-panel-3-0)
-   [Python](#tab-panel-3-1)
-   [cURL](#tab-panel-3-2)
-   [Java](#tab-panel-3-3)
-   [C#](#tab-panel-3-4)
-   [PHP](#tab-panel-3-5)
-   [Go](#tab-panel-3-6)
-   [Ruby](#tab-panel-3-7)
-   [Swift](#tab-panel-3-8)

```js
// 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());
```

```python
import requests

res = requests.post(
    'https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies',
    headers={'authorization': 'Bearer BEARER_TOKEN'},
)
print(res.status_code, res.text)
```

```bash
curl --request POST \
  --url 'https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies' \
  --header 'authorization: Bearer BEARER_TOKEN'
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies"))
    .header("authorization", "Bearer BEARER_TOKEN")
    .method("POST", HttpRequest.BodyPublishers.noBody())
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
```

```csharp
using System.Net.Http.Headers;

using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");
var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```php
<?php
$ch = curl_init('https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies');
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'],
  CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
```

```go
package main

import (
  "fmt"
  "io"
  "net/http"
)

func main() {
  req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies", nil)
  req.Header.Set("authorization", "Bearer BEARER_TOKEN")
  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()
  out, _ := io.ReadAll(res.Body)
  fmt.Println(res.Status, string(out))
}
```

```ruby
require 'net/http'

uri = URI('https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies')
req = Net::HTTP::Post.new(uri)
req['authorization'] = 'Bearer BEARER_TOKEN'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, res.body
```

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies")!)
request.httpMethod = "POST"
request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")
let (data, response) = try await URLSession.shared.data(for: request)
print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))
```

Example response

```json
{
  "name": "RiakFsError",
  "message": "Path already exists: /REST API Examples/copies"
}
```
