Skip to content

Folder settings and protected URLs

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

Folder options control how Sirv treats a folder: whether it scans the folder for 360 spins, whether spins are named after the folder, and whether anyone can list its contents. The JWT command returns a token for protected folders, so a file there opens only with a signed URL that expires when you choose.

After reading this you will know

  • How to read and change a folder's options
  • How to switch spin scanning and public listing on or off
  • How to get a token for a JWT protected URL

Every command on this page needs a bearer token.

GEThttps://api.sirv.com/v2/files/options

Use this API method to check the options of a folder.

It will tell you the settings for spin scanning, spin naming, public listing and folder locking (Enterprise accounts only).

Query parameters

NameTypeRequiredExampleDescription
filenamestringYes/REST API ExamplesPath of the folder, starting with /.
withInheritedbooleanNotrueInclude options inherited from parent folders

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/options?filename=%2FREST%20API%20Examples', {
method: 'GET',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Example response

{
"scanSpins": true,
"allowListing": false
}
POSThttps://api.sirv.com/v2/files/jwt

JWT protection is a powerful way to protect your files from being seen without permission.

Use this API method to generate a token that can be appended to a URL or set of URLs, allowing a file to be served.

Without a valid token, requests for any file within a JWT protected folder will be denied.

Before using this method, you must enable JWT folder protection and obtain a key.

Read the documentation to learn how to enable and use JWT protection: Protected URLs with JSON Web Tokens

Request body (JSON)

FieldTypeRequiredExampleDescription
filenamestringYes/REST API Examples/aurora.jpgPath of the file, or the folder, that the protected URL opens.
keystringYescIxWUYfCjRHAy1BpcoIVNI5TivXszVPqSpecify JWT secret
aliasstringNodemo-jwtSpecify account alias if your account has multiple aliases
insecureParamsobjectNoImage options a visitor can still add or change in the URL, such as w and h.
secureParamsobjectNoImage options or a profile locked into the token, which the URL cannot change.
expiresInnumberYes300Token expiration time in seconds

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/jwt', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' },
body: JSON.stringify({
"filename": "/REST API Examples/aurora.jpg",
"key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq",
"alias": "demo-jwt",
"secureParams": {
"w": 300,
"h": 300
},
"expiresIn": 300
}),
});
console.log(res.status, await res.text());

Example response

{
"url": "https://demo-jwt.sirv.com/REST API Examples/aurora.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcmdzIjp7InciOjMwMCwiaCI6MzAwfSwiaWF0IjoxNzcxODU1Njg1LCJleHAiOjE3NzE4NTU5ODUsImF1ZCI6Ii9SRVNUIEFQSSBFeGFtcGxlcy9hdXJvcmEuanBnIn0.9KvaToLxdobTONZ5JnCeZKuf1z1XynBC2yYnEk8k0i4"
}
POSThttps://api.sirv.com/v2/files/options

Use this API method to change the folder options. You can enable/disable spin scanning, change the spin naming convention and enable/disable publicly viewable folder listings.

Query parameters

NameTypeRequiredExampleDescription
filenamestringYes/REST API ExamplesPath of the folder, starting with /.

Request body (JSON)

FieldTypeRequiredExampleDescription
scanSpinsbooleanNotruetrue to let Sirv build spins from the images in this folder, false to never build them here.
nameSpinsAfterFolderbooleanNotruetrue to name each new spin after its folder.
allowListingbooleanNofalsetrue to let anyone get a list of the folder’s files from its URL, as JSON.

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/options?filename=%2FREST%20API%20Examples', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' },
body: JSON.stringify({
"scanSpins": true,
"allowListing": false
}),
});
console.log(res.status, await res.text());

Response

HTTP 200 with an empty body when the command succeeds.

Back to top