Skip to content

Fetch a file from a URL

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

Fetch a file from a URL with POST /v2/files/fetch. This can be any URL, either public or private (via HTTP authentication). In the url parameter, enter the full URL of the remote file. Each call needs a bearer token and counts towards your hourly API limit.

After reading this you will know

  • How to fetch a file from a URL
  • Which parameters it takes
  • Sample code in 9 languages and a sample answer

This command needs a bearer token and counts towards your hourly limit.

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

Use this API method to fetch a file(s) from a URL via HTTP and save it to your Sirv account.

This can be any URL, either public or private (via HTTP authentication). In the url parameter, enter the full URL of the remote file.

In the filename parameter, enter the folder path and filename where it should be saved e.g. /path/to/folder/new-filename.jpg.

If the folder path does not already exist in your Sirv account new folder(s) will be created.

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/fetch', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' },
body: JSON.stringify([
{
"url": "https://demo.sirv.com/aurora.jpg",
"filename": "/REST API Examples/aurora.jpg"
},
{
"url": "https://demo.sirv.com/missing.jpg",
"filename": "/REST API Examples/missing.jpg"
}
]),
});
console.log(res.status, await res.text());

Example response

[
{
"filename": "/REST API Examples/aurora.jpg",
"success": true,
"attempted": false,
"attempts": [
{
"url": "https://demo.sirv.com/aurora.jpg",
"initiator": {
"type": "api",
"remoteAddr": "176.105.166.4",
"date": "2020-07-17T15:47:35.316Z"
},
"statusCode": 200,
"headers": {
"result": {
"version": "HTTP/1.1",
"code": 200,
"reason": "OK"
},
"Date": "Fri, 17 Jul 2020 15:47:36 GMT",
"Content-Type": "image/webp",
"Content-Length": "201846",
"Connection": "keep-alive",
"Last-Modified": "Fri, 17 Jul 2020 15:47:36 GMT",
"ETag": "\"5f11c818-31476\"",
"Server": "Sirv.Imagination",
"X-Sirv-Server": "c1-extra1-fireball-13",
"X-Sirv-Cache": "MISS",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Expires": "Sun, 16 Aug 2020 15:47:36 GMT",
"Cache-Control": "max-age=2592000",
"X-Sirv-Meta-Width": "2500",
"X-Sirv-Meta-Height": "1667",
"X-Sirv-Shard": "c1-riak1",
"X-Account-Id": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud",
"X-File-VersionId": "5evxYG8lnBgeA7cGBRTZzq7JQolRYviN:0",
"X-Account-Serial": "2020-06-15T19:18:53.901Z",
"Accept-Ranges": "bytes"
},
"timing": {
"ns": 0.007514,
"connect": 0.007912,
"start": 0.48724,
"total": 0.489622
},
"date": "2020-07-17T15:47:36.712Z"
}
],
"retryAfter": "2020-07-18T15:47:36.712Z"
},
{
"filename": "/REST API Examples/missing.jpg",
"success": false,
"attempted": false,
"attempts": [
{
"url": "https://demo.sirv.com/missing.jpg",
"initiator": {
"type": "api",
"remoteAddr": "176.105.166.4",
"date": "2020-07-18T08:35:51.026Z"
},
"statusCode": 404,
"headers": {
"result": {
"version": "HTTP/1.1",
"code": 404,
"reason": "Not Found"
},
"Date": "Sat, 18 Jul 2020 08:35:52 GMT",
"Content-Type": "text/html; charset=utf-8",
"Content-Length": "4140",
"Connection": "keep-alive",
"Vary": "Accept-Encoding",
"X-Account-Id": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud",
"X-Account-Serial": "2020-06-15T19:18:53.901Z",
"ETag": "W/\"102c-wKpRt+Cg9Cnw/NpTSkF5+w\"",
"X-Sirv-Cache": "MISS",
"Server": "Sirv.Imagination",
"X-Sirv-Server": "c1-extra1-fireball-15",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*"
},
"timing": {
"ns": 0.018986,
"connect": 0.019303,
"start": 0.103774,
"total": 0.103829
},
"error": {
"name": "Error",
"message": "Request not successful: expected status code 200 but got 404"
},
"date": "2020-07-18T08:35:52.089Z"
}
],
"retryAfter": "2020-07-18T12:07:32.613Z"
}
]
Back to top