POST /oauth2/token issues an access token for an app using the OAuth 2.0 client credentials grant. Send the request to the HTTPS URL of the workspace that issued the client ID. For setup and a first API call, see List workspace clusters with OAuth.
Choose the token request for your workspace
Ask your workspace administrator how cluster API access is checked for this app.
For an app that runs SQL through the query engine, the token still needs
query_engine.query:execute. Confirm SQL access and access to the target cluster before running a query.
Request
Send the client ID and secret with HTTP Basic authentication. Use anapplication/x-www-form-urlencoded body.
This Bash example requests a token for an app with an assigned cluster-read scope. If your administrator confirms that the workspace checks permissions on clusters, set
SCOPE_ARGS=() instead. Curl prompts for the client secret. Keep Bash tracing off when handling tokens. The command displays the token type, lifetime, and scope without printing the token itself. It requires curl 7.76 or later and jq.
Response
HTTP200 returns JSON. This example shows a client with the cluster-read scope. The access token is redacted and the lifetime is illustrative. Use the expires_in value returned by your workspace, in seconds.
Authorization: Bearer header. To continue from the Bash example, use the cluster list request in the same terminal. For a recurring job, request a replacement before expiry. This grant does not return a refresh token.
Errors
An error response contains an
error field, for example {"error":"invalid_scope"}. If curl reported an HTTP error, use jq -r '.error // empty' <<< "$TOKEN_REPLY" to see its name. Keep the full token reply out of logs. When you finish making API calls in this shell, run unset ACCESS_TOKEN TOKEN_REPLY.