Skip to content

REST API Overview

By , Customer Success DirectorUpdated

Open this page in a new chat

Short answer

The Sirv REST API has more than 60 commands to upload, download, rename, move, copy, delete and search files and manage your account. Create an API client in Settings > API access, send its client ID and secret to get a bearer token, then add the token to each request. Each plan has an hourly request limit.

After reading this you will know

  • How to create an API client and get a bearer token
  • What the API can do, with sample scripts
  • The hourly limits, how to handle errors, and how to limit a key's scope

Sirv’s REST API provides you with more than 60 commands for managing your account and your files (upload, download, rename, delete, move, copy, search etc.).

To use the Sirv REST API, you need an API client. An API client is comprised of a clientId and clientSecret.

To create an API client or use an existing client, go to Settings > API access in your Sirv account and click “New API client”:

New API client button in Settings > API access

Once created, you’ll see your Client ID and Client Secret:

List of Sirv REST API clients

By default, API clients have full access to use any API method. Instead, it is possible to restrict the scope to specific API methods. See list of scopes.

Each API call must be authenticated with a bearer token (JSON Web Token).

You can get a token by submitting a POST request to the Sirv API, using your preferred programming language, or with no code in Postman. The following example script uses Curl to request a token:

curl --request POST \
--url https://api.sirv.com/v2/token \
--header 'content-type: application/json' \
--data '{
"clientId": "LW82h5FESf4iYmDYeJUjGjsIf8P",
"clientSecret": "YOUR_CLIENT_SECRET"
}'

The Sirv API will respond with: a bearer token; the token duration; and its scope:

{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…",
"expiresIn": 1200,
"scope": [
"account:read",
"account:write",
"user:read",
"user:write",
"billing:read",
"billing:write",
"files:read",
"files:write",
"files:create",
"files:upload:multipart",
"files:sharedBilling",
"videos",
"images"
]
}

Once you have a token, you can use any of the 60+ Sirv REST API methods. You can use the token repeatedly until it expires. Once your token has expired, request a new token to continue using the API.

Tokens expire after 20 minutes by default. The token expiry time is returned in the expiresIn field after you submit a successful token request.

You can change the expiry to between 5 and 604800 seconds (7 days) by setting the expiresIn parameter. This example script will request a token with a 30 second expiry:

curl --request POST \
--url https://api.sirv.com/v2/token \
--header 'content-type: application/json' \
--data '{
"clientId": "LW82h5FESf4iYmDYeJUjGjsIf8P",
"clientSecret": "YOUR_CLIENT_SECRET",
"expiresIn": 30
}'

With your bearer token, you can use more than 60 different Sirv REST API methods. Each method is described in the API docs at Sirv REST API reference.

You can see a summary of each method, how it can be used and a list of properties that can be set. Additional documentation is available for some API methods.

The search API documentation describes the many ways of searching your Sirv account, with detailed descriptions and examples.

The upload API documentation describes the two different API methods for uploading local files to Sirv, plus limitations and best-practices.

The fetch API documentation describes how to upload files to Sirv from a remote URL. It explains the important factors you should account for when fetching files from a URL.

There are many example scripts provided at the documentation links above. Additional example scripts are also provided for these languages:

The Sirv REST API has a limit to how many requests can be returned per hour. Enterprise plan limits:

  • Total requests per hour: 14000
  • Search requests: 2000
  • Video to spin conversions: 400
  • Spin to video conversions: 400
  • Fetch requests: 4000

Business plan limits:

  • Total requests per hour: 7000
  • Search requests: 1000
  • Video to spin conversions: 200
  • Spin to video conversions: 200
  • Fetch requests: 2000

Free plan limits:

  • Total requests per hour: 500
  • Search requests: 50
  • Video to spin conversions: 20
  • Spin to video conversions: 20
  • Fetch requests: 300

The total requests per hour is for all types of request combined. The hour starts counting from the time that the first request is received by Sirv.

For example, if a request is received at 18:35:51, the API allowance will be reset at 19:35:51. Check your current REST API usage on the Usage page of your Sirv account.

If you exceed your limit, you will receive 429 responses. See the guide below on how to handle 429 and other errors.

Use the API method below to check all types of limit across your account (REST API limits, S3 API limits and FTP limits).

The API method will return:

  • Your limit
  • Number of requests in last hour
  • Number of requests remaining
  • Time when limit will reset (UTC epoch seconds)

Proper error handling is essential to building high quality applications and a seamless end-user experience.

Each Sirv response contains a standard response code, to indicate the type of error, with JSON or plaintext bodies.

A 400 error could be caused from a malformed JSON request body or JSON that does not conform to input fields and validation.

400 errors may also be returned to a user without permission to use the REST API.

Responses with error code 400 suggest an issue with the request itself, so they won’t be resolved by retrying.

A 401 error is returned when the bearer token is invalid or has expired. You can choose an expiry between 5 and 604800 seconds (7 days).

By default, tokens will expire after 20 minutes. Retrying a 401 will not succeed.

If your application receives a 401 response, it should get a new token then try again. Example response headers:

date: Sat, 27 Apr 2024 09:55:07 GMT
content-type: application/json; charset=utf-8
content-length: 132
www-authenticate: Token error="Expired token"
access-control-allow-origin: *
access-control-expose-headers: *
cache-control: no-cache
server: Sirv.API

Example response body:

{
"statusCode": 401,
"error": "Unauthorized",
"message": "Expired token",
"attributes": {
"error": "Expired token"
}
}

A 429 error means that your API usage has reached its hourly limit. Your hourly limit and current usage is shown on the Usage page of your account.

You can also retrieve this information via an API limit request (it will work even if your account has reached its hourly limit).

Sirv API limits are generous, so your application is unlikely to hit them.

However, we recommend that your script is written to deal with 429 errors, by pausing your requests and waiting until your hourly limit refreshes.

To help you do this, every Sirv REST API response contains the following headers:

  • X-RateLimit-Limit - the hourly request limit.
  • X-RateLimit-Remaining - the number of requests remaining in the current hour.
  • X-RateLimit-Reset - a UNIX timestamp (in seconds) for when the limit will be reset.
  • X-RateLimit-Type - the type of request this limit relates to e.g. rest:post:files:search.

The header information above is also duplicated in the JSON structure.

The error message includes a “Retry after” timestamp, in human readable format, so you can pause requests and resume after the retry time.

If you’re incurring 429 errors due to a large one-time migration of files, you can request a temporary higher limit.

Internal server errors are rare, undefined errors on the Sirv side. Such errors should be brief. If you see 500 errors for an extended period, please check https://status.sirv.com/ or contact the Sirv support team.

If you receive a 502 response, you should retry the request a few times and it may succeed. If a 502 is returned repeatedly many times, then slow down or pause your requests.

It may be that a server is unhealthy or misconfigured and this issue will be resolved soon by the Sirv team.

If an API service is overloaded, a 503 error might be returned. Overloads are rare and will self-heal, typically within a few minutes.

If you receive a 503 error, try again in 15 or more minutes. If you see 500 errors for an extended period, please check https://status.sirv.com/ or contact the Sirv support team.

Track your error rates. While some types of 4xx errors may occur occasionally, high error rates indicate problems in your application and it should be optimized.

All Sirv API calls (whether successful or 4xx) return useful headers in their responses. If you need help from Sirv support, share these headers to help speed up troubleshooting.

Logging your responses will give you a clear understanding of your API usage, how to optimize your application and solve problems.

When building your application, test all the error types above. This is an important best-practice measure, to ensure your application runs smoothly.

If your script receives any 429 responses, resubmit those requests once your hourly limit has refreshed.

Sirv provides the following Swagger OpenAPI Specification JSON file: https://api.sirv.com/swagger.json It describes the entire API, including:

  • Authentication, to get an API access token
  • Available endpoint paths and operations on each endpoint (GET and POST)
  • Operation parameters and responses for each operation

The API clients which you create in your Sirv API settings have full scope to perform any of the API commands.

It is also possible to have limited scope API keys, with any combination of the following capabilities:

  • File management - read
  • File management - write (upload/create, overwrite, rename, move, copy, delete)
  • File management - create (upload/create)
  • File management - sub-accounts (access files on sub-accounts)
  • Account management - read
  • Account management - write
  • User management - read (get list of users)
  • User management - write (add/change users/roles)
  • Billing management - read (get plan/invoice details)
  • Billing management - write (change billing plan)
  • Image operations - (background removal, image preprocessing)
  • Video operations - (HLS stream management, video to spin conversion)

Ask the support team if you require a limited scope API key.

Sirv also provides special API methods, available upon request. Please contact Sirv support if you need access to:

  • Create new accounts
  • Get user credentials
  • Get list of a users’ accounts
Back to top