Skip to content

Get a JWT protected URL

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

Get a JWT protected URL with POST /v2/files/jwt. JWT protection is a powerful way to protect your files from being seen without permission. Each call needs a bearer token and counts towards your hourly API limit. Below are the parameters, sample code in 9 languages and a sample answer.

After reading this you will know

  • How to get a JWT protected 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/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"
}
Back to top