Folder settings and protected URLs
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.
Get folder options
Section titled “Get folder options”https://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
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
filename | string | Yes | /REST API Examples | Path of the folder, starting with /. |
withInherited | boolean | No | true | Include options inherited from parent folders |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst 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());import requests
res = requests.get( 'https://api.sirv.com/v2/files/options?filename=%2FREST%20API%20Examples', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/options?filename=%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/options?filename=%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/options?filename=%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/options?filename=%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/options?filename=%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/options?filename=%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/options?filename=%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
{ "scanSpins": true, "allowListing": false}Get JWT protected URL
Section titled “Get JWT protected URL”https://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)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
filename | string | Yes | /REST API Examples/aurora.jpg | Path of the file, or the folder, that the protected URL opens. |
key | string | Yes | cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq | Specify JWT secret |
alias | string | No | demo-jwt | Specify account alias if your account has multiple aliases |
insecureParams | object | No | Image options a visitor can still add or change in the URL, such as w and h. | |
secureParams | object | No | Image options or a profile locked into the token, which the URL cannot change. | |
expiresIn | number | Yes | 300 | Token expiration time in seconds |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst 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());import requests
res = requests.post( 'https://api.sirv.com/v2/files/jwt', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "filename": "/REST API Examples/aurora.jpg", "key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq", "alias": "demo-jwt", "secureParams": { "w": 300, "h": 300 }, "expiresIn": 300 },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/jwt' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"filename":"/REST API Examples/aurora.jpg","key":"cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq","alias":"demo-jwt","secureParams":{"w":300,"h":300},"expiresIn":300}'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/jwt")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "filename": "/REST API Examples/aurora.jpg", "key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq", "alias": "demo-jwt", "secureParams": { "w": 300, "h": 300 }, "expiresIn": 300 } """)) .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/jwt");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "filename": "/REST API Examples/aurora.jpg", "key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq", "alias": "demo-jwt", "secureParams": { "w": 300, "h": 300 }, "expiresIn": 300}""", 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/jwt');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'filename' => '/REST API Examples/aurora.jpg', 'key' => 'cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq', 'alias' => 'demo-jwt', 'secureParams' => [ 'w' => 300, 'h' => 300 ], 'expiresIn' => 300 ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "filename": "/REST API Examples/aurora.jpg", "key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq", "alias": "demo-jwt", "secureParams": { "w": 300, "h": 300 }, "expiresIn": 300 }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/jwt", 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/jwt')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "filename": "/REST API Examples/aurora.jpg", "key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq", "alias": "demo-jwt", "secureParams": { "w": 300, "h": 300 }, "expiresIn": 300 }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/jwt")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "filename": "/REST API Examples/aurora.jpg", "key": "cIxWUYfCjRHAy1BpcoIVNI5TivXszVPq", "alias": "demo-jwt", "secureParams": { "w": 300, "h": 300 }, "expiresIn": 300}"""#.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
{ "url": "https://demo-jwt.sirv.com/REST API Examples/aurora.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcmdzIjp7InciOjMwMCwiaCI6MzAwfSwiaWF0IjoxNzcxODU1Njg1LCJleHAiOjE3NzE4NTU5ODUsImF1ZCI6Ii9SRVNUIEFQSSBFeGFtcGxlcy9hdXJvcmEuanBnIn0.9KvaToLxdobTONZ5JnCeZKuf1z1XynBC2yYnEk8k0i4"}Set folder options
Section titled “Set folder options”https://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
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
filename | string | Yes | /REST API Examples | Path of the folder, starting with /. |
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
scanSpins | boolean | No | true | true to let Sirv build spins from the images in this folder, false to never build them here. |
nameSpinsAfterFolder | boolean | No | true | true to name each new spin after its folder. |
allowListing | boolean | No | false | true 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 variableconst 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());import requests
res = requests.post( 'https://api.sirv.com/v2/files/options?filename=%2FREST%20API%20Examples', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "scanSpins": True, "allowListing": False },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/options?filename=%2FREST%20API%20Examples' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"scanSpins":true,"allowListing":false}'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/options?filename=%2FREST%20API%20Examples")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "scanSpins": true, "allowListing": false } """)) .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/options?filename=%2FREST%20API%20Examples");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "scanSpins": true, "allowListing": false}""", 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/options?filename=%2FREST%20API%20Examples');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'scanSpins' => true, 'allowListing' => false ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "scanSpins": true, "allowListing": false }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/options?filename=%2FREST%20API%20Examples", 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/options?filename=%2FREST%20API%20Examples')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "scanSpins": true, "allowListing": false }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/options?filename=%2FREST%20API%20Examples")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "scanSpins": true, "allowListing": false}"""#.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.
