The first time you use the Sirv REST API, create an API client, then connect to Sirv. Once connected, you can use over 30 API methods.
To use the Sirv REST API, create an API client from the Settings page of your Sirv account:
Once created, you'll see your Client ID and Client Secret:
The clientId and clientSecret pair represent the API client. The API client can can have full access to all operations or be limited to specific API methods.
Each API call must be authenticated with a bearer token (JSON Web Token). You can get a token with a POST request. Here's an example in curl:
{ curl --request POST \ --url https://api.sirv.com/v2/token \ --header 'content-type: application/json' \ --data '{ "clientId": "CLIENT_ID", "clientSecret": "CLIENT_SECRET" }'
If you would like an example in another language, please send your requirements from your Sirv account contact form. The JSON response to the POST request will look like this:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnRJZCI6IkNMSVlYRjVqMERQV053cWpzdHJWbkNPVFRNbCIsImNsaWVudE5hbWUiOiJUZXN0IGNsaWVudCIsInNjb3BlIjpbImFjY291bnQ6cmVhZCIsImFjY291bnQ6d3JpdGUiLCJ1c2VyOnJlYWQiLCJ1c2VyOndyaXRlIiwiYmlsbGluZzpyZWFkIiwiYmlsbGluZzp3cml0ZSIsImZpbGVzOnJlYWQiLCJmaWxlczp3cml0ZSIsInZpZGVvcyIsImltYWdlcyJdLCJpYXQiOjE1MjIwODExMTYsImV4cCI6MTUyMjA4MjMxNiwiYXVkIjoiNDlnaGEyN2ZraHQzdGtyaml0aWJoNGJrazQxemdqdTgifQ.GkhToMKvy8hB68SNpqpPcxhsMczyyTtlROMvsqiPJ4Y", "expiresIn": 1200, "scope": [ "account:read", "account:write", "user:read", "user:write", "billing:read", "billing:write", "files:read", "files:write", "videos", "images" ] }
Use the token with the Sirv REST API methods listed below. When the token expires (see the expiresIn field, in seconds), you should request a new token.
For example, this curl script shows how to use the API method to convert a video to spin:
curl --request POST \ --url https://api.sirv.com/v2/files/video2spin \ --header 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnRJZCI6IkNMSVlYRjVqMERQV053cWpzdHJWbkNPVFRNbCIsImNsaWVudE5hbWUiOiJUZXN0IGNsaWVudCIsInNjb3BlIjpbImFjY291bnQ6cmVhZCIsImFjY291bnQ6d3JpdGUiLCJ1c2VyOnJlYWQiLCJ1c2VyOndyaXRlIiwiYmlsbGluZzpyZWFkIiwiYmlsbGluZzp3cml0ZSIsImZpbGVzOnJlYWQiLCJmaWxlczp3cml0ZSIsInZpZGVvcyIsImltYWdlcyJdLCJpYXQiOjE1MjIwODExMTYsImV4cCI6MTUyMjA4MjMxNiwiYXVkIjoiNDlnaGEyN2ZraHQzdGtyaml0aWJoNGJrazQxemdqdTgifQ.GkhToMKvy8hB68SNpqpPcxhsMczyyTtlROMvsqiPJ4Y' \ --header 'content-type: application/json' \ --data '{ "filename": "/My-Video.mp4" }'
The response JSON will either contain the filename of the converted spin:
{ "filename": "/A-Folder/My-Video.spin" }
or an error:
{ "statusCode": 404, "error": "Not Found", "message": "No such file: /My-Video.mp4" }
The following example uses JavaScript to obtain a bearer token (JSON Web Token):
var request = require('request'); var headers = { 'content-type': 'application/json' }; var dataString = '{ "clientId": "CLIENT_ID", "clientSecret": "CLIENT_SECRET"}'; var options = { url: 'https://api.sirv.com/v2/token', method: 'POST', headers: headers, body: dataString }; request(options, (error, response, body) => { if (!error && response.statusCode == 200) { console.log(body); } });
The S3 API let's you upload / download / query / delete / modify / move files.