Set up a workspace machine client
- Get the HTTPS workspace URL from your workspace admin. Use the origin only, without a page path or trailing slash. Use that same URL for both requests.
- Ask your workspace admin for a machine client, the identity your app uses. Confirm how this workspace checks management API requests. During an update, new access controls may appear before their grants take effect.
- Save the client ID and store the client secret in your secret manager. The secret is shown once at creation.
Use Bash, curl 7.76 or later, and jq. Run both examples in the same terminal with shell tracing off.
How the two requests work
Your app sends its client ID and secret to the workspace token endpoint. It then sends the returned access token to the cluster API on the same workspace.1. Get an access token
Choose one setting in Bash. If your workspace checks OAuth scopes, request the read scope:POST /oauth2/token returns HTTP 200 and four fields. The command prints only the last three so the access token stays out of your terminal output. Example scope-based response with the token removed:
expires_in is the lifetime in seconds. Your workspace may return a different value. If curl reports a token request error, run jq -r '.error // empty' <<< "$TOKEN_REPLY" to read the error code. When workspace permissions are active, the returned scope can be empty. Use step 2 to check the actual API call.
2. List the clusters
Send the token in theAuthorization header of GET /api/v1/queryservices. This request takes no body. The command reads the header from standard input so the token stays out of curl’s command-line arguments.
200 means the call worked. Read total for the cluster count and items for the cluster records. A list with no results looks like this:
unset ACCESS_TOKEN TOKEN_REPLY.
For request fields and responses, see Get an app access token or List clusters. To check the state of one cluster, use Get a cluster with the same token. To verify a grant to one cluster, follow Check which clusters a job can read.
Keep a scheduled job signed in
Have the job read its credentials from your secret manager. Use your HTTP client’s Basic authentication option for the token request. The password prompt in the example is for a person running curl. Keep the token in memory and reuse it. Request a new one shortly before itsexpires_in lifetime ends. If the cluster list returns 401 because the token expired, get a new token and retry that read once. This grant does not issue a refresh token. Keep secrets and tokens out of job logs.
When the client secret needs replacing, rotate it while jobs keep running.
Troubleshoot a request
A cluster read confirms management API access. To run SQL with a machine client, the query engine also requires
query_engine.query:execute in the token and access to the target cluster. See SQL over REST.