Get an Access Token
const url = 'https://api.example.com/oauth/token';const options = { method: 'POST', headers: { Authorization: 'Basic <credentials>', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'client_credentials', client_id: 'ci_test_4f2aK9mQ7xR1vT8bN3cL6hWd', client_secret: 'example' })};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.example.com/oauth/token \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data grant_type=client_credentials \ --data client_id=ci_test_4f2aK9mQ7xR1vT8bN3cL6hWd \ --data client_secret=exampleExchanges your client ID and secret for an Access Token (the OAuth 2.0 client credentials
grant, RFC 6749). Send the client ID and secret in a Basic Authorization header, or as
client_id and client_secret in the body, not both, and each parameter once. The token
lasts 15 minutes; any
standard OAuth client library can call this and fetch a new token as each expires.
Errors follow RFC 6749, not the /v1 envelope. Every client ID and secret that proves
nothing — an unknown client, a wrong secret, a revoked key — gets the same invalid_client.
Token requests are rate limited per client ID and per address.
Authorizations
Section titled “Authorizations”- ClientSecret
- None
Request Bodyrequired
Section titled “Request Bodyrequired”object
With client_secret, instead of a Basic header.
With client_id, instead of a Basic header.
The same parameters as a JSON object, for a client that sends JSON.
object
Responses
Section titled “Responses”The token. Every answer here is sent with Cache-Control: no-store and Pragma: no-cache.
object
Seconds until it expires.
Example
{ "token_type": "Bearer", "expires_in": 900}invalid_request (no grant_type, or the client authenticated both ways), or unsupported_grant_type (anything but client_credentials).
object
Example
{ "error": "invalid_request"}invalid_client: the client ID or secret is not valid. Sent with a WWW-Authenticate: Basic header.
object
Example
{ "error": "invalid_request"}rate_limited: too many token requests. Try again shortly.
object
Example
{ "error": "invalid_request"}