Skip to content

Authentication

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

Every Sirv REST API request needs a bearer token. Send your API client's ID and secret to POST /v2/token and you get a token that lasts 20 minutes by default. Add it to each request as an authorization header: the word Bearer, then the token. When it expires, ask for a new one.

After reading this you will know

  • How to get a bearer token from your client ID and secret
  • How long a token lasts and how to change it
  • Sample code in 9 languages

This is the only command you call without a token. Send the token it returns with every other request.

POSThttps://api.sirv.com/v2/token

Every API call will be authenticated with a bearer token, so your first step is to obtain a bearer token.

Bearer tokens expire after 20 minutes (1200 seconds). If your token expires, request a new one, then continue with your work.

After each API request you submit, you’ll receive a response that contains useful information, including an expiresIn field (in seconds) telling you how long remains before your bearer token expires.

Request body (JSON)

FieldTypeRequiredExampleDescription
clientIdstringYesCLIENT_IDAPI client ID
clientSecretstringYesCLIENT_SECRETAPI client secret
expiresInnumberNo1200Expiration TTL for token in seconds. Up to 604800.

Example request

// Your API client ID and secret, in the SIRV_CLIENT_ID and SIRV_CLIENT_SECRET environment variables
const res = await fetch('https://api.sirv.com/v2/token', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
"clientId": process.env.SIRV_CLIENT_ID,
"clientSecret": process.env.SIRV_CLIENT_SECRET
}),
});
console.log(res.status, await res.text());

Example response

{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 1200,
"scope": [
"account:read",
"account:write"
]
}
Back to top