Files and folders
Short answer
These commands manage the files and folders in your Sirv account: list a folder, get a file's details, copy, rename, move and delete files, create folders, search by name, type, date or metadata, and zip or delete many files at once. Batch and zip jobs run in the background; check their result with the job ID.
After reading this you will know
- How to list folders and get file details
- How to copy, rename, move and delete files and folders
- How to search files and run batch delete and zip jobs
Every command on this page needs a bearer token.
Copy file
Section titled “Copy file”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
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst 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());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)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'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());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$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);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))}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.bodyimport 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.
Create new empty folder
Section titled “Create new empty folder”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
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst 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());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)curl --request POST \ --url 'https://api.sirv.com/v2/files/mkdir?dirname=%2FREST%20API%20Examples%2Fcopies' \ --header 'authorization: Bearer BEARER_TOKEN'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());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$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);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))}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.bodyimport 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
{ "name": "RiakFsError", "message": "Path already exists: /REST API Examples/copies"}Delete a batch of files or directories
Section titled “Delete a batch of files or directories”https://api.sirv.com/v2/files/batch/delete
Use this method to delete the list of filenames
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
filenames | array of string | Yes | ["/REST API Examples/coin/coin_01.jpg"] | Paths of the files or folders to delete, up to 1,000. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/batch/delete', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify({ "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ] }),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/files/batch/delete', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ] },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/batch/delete' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"filenames":["/REST API Examples/filename.jpg","/REST API Examples/directory/"]}'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/batch/delete")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ] } """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/batch/delete");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ]}""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/batch/delete');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'filenames' => [ '/REST API Examples/filename.jpg', '/REST API Examples/directory/' ] ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ] }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/batch/delete", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/batch/delete')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ] }JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/batch/delete")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "filenames": [ "/REST API Examples/filename.jpg", "/REST API Examples/directory/" ]}"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
{ "id": "YE49COidrrMuVspJg41HAsaVA0ecmQKs"}Delete file or empty folder
Section titled “Delete file or empty folder”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
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst 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());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)curl --request POST \ --url 'https://api.sirv.com/v2/files/delete?filename=%2FREST%20API%20Examples%2Faurora-copy.jpg' \ --header 'authorization: Bearer BEARER_TOKEN'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());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$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);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))}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.bodyimport 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.
Get file info
Section titled “Get file info”https://api.sirv.com/v2/files/stat
Use this API method to get information about a file, including created time, modified time, content type and size. It returns Unix information.
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
filename | string | Yes | /REST API Examples/blue-lake.jpg | Path of the file in your account, starting with /. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg' \ --header 'authorization: Bearer BEARER_TOKEN'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/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.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$ch = curl_init('https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg')req = Net::HTTP::Get.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.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/stat?filename=%2FREST%20API%20Examples%2Fblue-lake.jpg")!)request.httpMethod = "GET"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
{ "mtime": "2020-07-17T13:31:39.450Z", "ctime": "2020-07-17T13:31:39.347Z", "contentType": "image/jpeg", "size": 587065, "isDirectory": false, "meta": { "width": 1578, "height": 1002, "duration": 0 }}Get results of batch delete job
Section titled “Get results of batch delete job”https://api.sirv.com/v2/files/batch/delete
Use this method to get results and progress of batch delete job created with POST /files/batch/delete method
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
id | string | Yes | BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI | Job ID returned from POST /files/batch/delete |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI' \ --header 'authorization: Bearer BEARER_TOKEN'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/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI", 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI')req = Net::HTTP::Get.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.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/batch/delete?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI")!)request.httpMethod = "GET"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
{}Get results of ZIP job
Section titled “Get results of ZIP job”https://api.sirv.com/v2/files/zip
Use this method to get results and progress of ZIP job created with POST /files/zip method
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
id | string | Yes | BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI | Job ID returned from POST /files/zip |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI' \ --header 'authorization: Bearer BEARER_TOKEN'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/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI", 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI')req = Net::HTTP::Get.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.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/zip?id=BLDgbVfrCYcLOceNSEf2ymIwLGQDXSCI")!)request.httpMethod = "GET"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
{ "progress": 100, "result": [ { "filename": "Sirv January 18, 2023.zip", "size": 138237, "url": "https://goto.sirv.com/AvhriHTv7nOrMvgBBtPHy1tH1hbaeFCi" } ]}Read folder contents
Section titled “Read folder contents”https://api.sirv.com/v2/files/readdir
Use this API method to get a list of all the files/folders within a folder.
It will return the filename, mimetype, content type and file size. It will also return any folders that exist.
A page of up to 100 results will be returned - use the ‘continuation’ field to request additional pages.
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
dirname | string | Yes | /REST API Examples | Path of the folder to list, starting with /. |
continuation | string | No | Send it to get next page of results |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples' \ --header 'authorization: Bearer BEARER_TOKEN'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/readdir?dirname=%2FREST%20API%20Examples")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples", 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples')req = Net::HTTP::Get.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.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/readdir?dirname=%2FREST%20API%20Examples")!)request.httpMethod = "GET"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
{ "contents": [ { "filename": "aurora.jpg", "mtime": "2026-02-23T10:22:34.659Z", "contentType": "image/jpeg", "size": 260864, "isDirectory": false, "meta": { "width": 2500, "height": 1667, "duration": 0 } }, { "filename": "aurora3.jpg", "mtime": "2020-11-18T19:55:13.459Z", "contentType": "image/webp", "size": 201846, "isDirectory": false, "meta": { "width": 2500, "height": 1667, "duration": 0 } } ]}Rename file or folder
Section titled “Rename file or folder”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
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst 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());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)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'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());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$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);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))}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.bodyimport 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.
Scroll through search results
Section titled “Scroll through search results”https://api.sirv.com/v2/files/search/scroll
Use the scroll API method after performing an API search if you need to retrieve more than 1000 results.
Each call to the scroll API returns the next batch of search results until there are no more results left to return.
To use scrolling, the initial search request should specify the “scroll” parameter.
The search context will then be kept alive for 30 seconds between each scroll call.
A scrolling search will cache the entire results temporarily while you retrieve them.
As such, it shows a snapshot in time and may become outdated if files have been added, deleted or modified since then. Learn more
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
scrollId | string | Yes | Scroll ID returned from preceding /files/search or /files/search/scroll call. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/search/scroll', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify({}),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/files/search/scroll', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={},)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/search/scroll' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{}'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/search/scroll")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" {} """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/search/scroll");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{}""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/search/scroll');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode((object) []), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{}`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/search/scroll", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/search/scroll')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' {}JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/search/scroll")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{}"""#.data(using: .utf8)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.
Search files
Section titled “Search files”https://api.sirv.com/v2/files/search
Use this API method to search for files based on one or more criteria: file name; folder path; file extension; content type; created/modified time; or with some specific meta information.
Up to 1000 results can be returned. If you need more results, use the scroll API method.
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
query | string | No | extension:.jpg | What to find, as Elasticsearch query text. Fields include filename, dirname, extension, size, mtime, contentType, meta.title, meta.tags, meta.product.id, and EXIF, IPTC and XMP fields. How to search by each is in Search files with the API. |
sort | object | No | Fields to sort the results by, each with asc or desc, as in Elasticsearch: {“mtime”: “desc”}. | |
from | number | No | 0 | Up to 1000. |
size | number | No | 5 | Up to 100. |
scroll | boolean | No | true | Start a scrolling search. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/search', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify({ "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5 }),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/files/search', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5 },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/search' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"query":"extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash","from":0,"size":5}'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/search")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5 } """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/search");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5}""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/search');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'query' => 'extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\/.Trash', 'from' => 0, 'size' => 5 ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5 }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/search", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/search')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5 }JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/search")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "query": "extension:.jpg AND mtime:[now-30d TO now] AND -dirname:\\/.Trash", "from": 0, "size": 5}"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
{ "hits": [ { "_index": "sirvfs-v4", "_type": "_doc", "_id": "248e197b4546afd4da9ccdb2ee0d30cf844ecf44", "_score": 1.3096726, "_routing": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "_source": { "accountId": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "filename": "/REST API Examples/aurora-copy.jpg", "dirname": "/REST API Examples", "basename": "aurora-copy.jpg", "extension": ".jpg", "id": "boW27K3kkyWK5LbGvxeOb0Sx3IOO0JoU", "ctime": "2026-02-23T13:55:04.615Z", "mtime": "2026-02-23T13:55:04.653Z", "size": 260864, "contentType": "image/jpeg", "meta": { "width": 2500, "height": 1667, "format": "JPEG", "duration": 0, "EXIF": { "ModifyDate": "2020-01-29T17:12:45Z" }, "ICC_Profile": { "ProfileDescription": "GIMP built-in sRGB" } } }, "sort": [ 1.3096726, "/REST API Examples/aurora-copy.jpg" ] }, { "_index": "sirvfs-v4", "_type": "_doc", "_id": "4b57cdf35a3568220bb9ad7a6f62f0048c8b4ae1", "_score": 1.3096726, "_routing": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "_source": { "accountId": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "filename": "/REST API Examples/aurora.jpg", "dirname": "/REST API Examples", "basename": "aurora.jpg", "extension": ".jpg", "id": "tkLbo0YuHJuBIEYj40lEUYRZZ8cLBGnF", "ctime": "2020-07-17T13:31:39.348Z", "mtime": "2026-02-23T10:22:34.659Z", "atime": "2026-02-12T07:43:18.986Z", "size": 260864, "contentType": "image/jpeg", "meta": { "width": 2500, "height": 1667, "format": "JPEG", "duration": 0, "EXIF": { "ModifyDate": "2020-01-29T17:12:45Z" }, "ICC_Profile": { "ProfileDescription": "GIMP built-in sRGB" } } }, "sort": [ 1.3096726, "/REST API Examples/aurora.jpg" ] } ], "total": 455, "_relation": "eq"}Zip a batch of files or directories
Section titled “Zip a batch of files or directories”https://api.sirv.com/v2/files/zip
Use this method to create a ZIP archive from the list of filenames
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
filenames | array of string | Yes | ["/REST API Examples/coin/coin_01.jpg"] | Paths of the files or folders to put in the zip, up to 1,000. |
zipFilename | string | No | Sirv January 18, 2023.zip | Name of the zip file, up to 64 characters. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/zip', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify({ "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip" }),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/files/zip', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip" },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/zip' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"filenames":["/REST API Examples/coin/coin_01.jpg","/REST API Examples/coin/coin_02.jpg"],"zipFilename":"Sirv January 18, 2023.zip"}'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/zip")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip" } """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/files/zip");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip"}""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/zip');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'filenames' => [ '/REST API Examples/coin/coin_01.jpg', '/REST API Examples/coin/coin_02.jpg' ], 'zipFilename' => 'Sirv January 18, 2023.zip' ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip" }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/zip", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") 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))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/zip')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip" }JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/zip")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "filenames": [ "/REST API Examples/coin/coin_01.jpg", "/REST API Examples/coin/coin_02.jpg" ], "zipFilename": "Sirv January 18, 2023.zip"}"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
{ "id": "SicD2eqm87EKGpPCAM4sCu28xGeSaNnB"}