Help centre
العربية Back to sayvara.com

Get an access token

Exchanges the client id and secret of an API client for a short-lived bearer token (OAuth 2.0 client credentials grant).

Updated

POST /v1/oauth/token

Exchanges the client id and secret of an API client for a short-lived bearer token (OAuth 2.0 client credentials grant). Send the credentials with HTTP Basic, or as client_id and client_secret in the body, but not both.

The body can be application/x-www-form-urlencoded (up to 8 KB) or JSON. Ask for fewer scopes with scope; asking for a scope the client does not hold fails with invalid_scope.

Reuse a token until it nearly expires: each client can get at most 30 tokens a minute.

Property Value
Authentication Client id and secret (HTTP Basic or in the body)
Scope None
Success 200 OK

Request body

Content type: application/x-www-form-urlencoded or application/json.

Field Type Required Description
grant_type "client_credentials" Yes Always client_credentials.
client_id string No Your client id (svc_...). Leave it out when you send the credentials with HTTP Basic. At most 64 characters.
client_secret string No Your client secret (svs_...). Leave it out when you send the credentials with HTTP Basic. At most 128 characters.
scope string No Space-separated scopes. At most 2000 characters.
grant_type=client_credentials&client_id=svc_0123456789abcdef01234567&client_secret=svs_REPLACE_WITH_YOUR_CLIENT_SECRET&scope=responses.read+events.write

Response

200 OK

Field Type Description
access_token string The bearer token for the API.
token_type "Bearer" Always Bearer.
expires_in integer Seconds until the token expires (300 to 3600, set on the client).
scope string Space-separated scopes.
{
  "access_token": "eyJhbGciOi...",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "responses.read events.write"
}

Errors

Errors use the OAuth 2.0 shape { "error": "...", "error_description": "..." }, not the usual Sayvara error shape.

Status Error Meaning
400 invalid_request The request is malformed, or the credentials were sent both ways.
400 unsupported_grant_type grant_type is not client_credentials.
400 unauthorized_client Your plan does not include API access.
400 invalid_scope A requested scope is not granted to this client.
401 invalid_client The client id or secret is wrong, the client is revoked, or the call came from an address outside the client's allow-list.
429 invalid_request Too many failed attempts, or too many tokens. Wait for the Retry-After seconds.
503 temporarily_unavailable Token signing failed for a moment. Try again with backoff.

Example request

curl -X POST "https://api.sayvara.com/v1/oauth/token" \
  -u "$SAYVARA_CLIENT_ID:$SAYVARA_CLIENT_SECRET" \
  -d "grant_type=client_credentials"