Skip to content

Search files

By , Head of IntegrationsUpdated

Open this page in a new chat

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.

POSThttps://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)

FieldTypeRequiredExampleDescription
querystringNoextension:.jpgWhat 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.
sortobjectNoFields to sort the results by, each with asc or desc, as in Elasticsearch: {“mtime”: “desc”}.
fromnumberNo0Up to 1000.
sizenumberNo5Up to 100.
scrollbooleanNotrueStart a scrolling search.

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

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"
}
POSThttps://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)

FieldTypeRequiredExampleDescription
scrollIdstringYesScroll 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 variable
const 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());

Response

HTTP 200 with an empty body when the command succeeds.

Back to top