Search files
Short answer
This page has 2 commands: Search files (POST /v2/files/search) and Scroll through search results (POST /v2/files/search/scroll). Up to 1000 results can be returned. If you need more results, use the scroll API method. Each call needs a bearer token and counts towards your hourly API limit.
After reading this you will know
- How to search files
- Which parameters each of the 2 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.
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"}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: scroll through more than 1000 results
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.