> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# List e6data workspace clusters with OAuth 2.0

> Get an e6data OAuth token, list clusters your app can access, and troubleshoot invalid_scope or a 403 when reading a cluster.

How-to guideApplies to: Workspaces with machine client access

Use this guide when an app or scheduled job needs to see which clusters exist in one workspace. The example reads the cluster list without changing any clusters.

## Set up a workspace machine client

1. 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.
2. 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.
3. Save the **client ID** and store the **client secret** in your secret manager. The secret is shown once at creation.

| How your workspace checks access | What your app needs |
| - | - |
| OAuth scopes | An admin assigns `query_engine.clusters:read` to the app under **Administration > Machine Clients**. |
| Workspace permissions, if confirmed active by your admin | Ask the admin to give the client access to read the clusters the job needs and check access it inherits from groups. |

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.

```mermaid theme={"theme":{"light":"github-light","dark":"github-dark"}}
sequenceDiagram
    participant A as Your app
    participant W as Workspace
    A->>W: Request token with ID and secret
    W-->>A: Access token and expiry
    A->>W: List clusters with token
    W-->>A: Cluster list
```

## 1. Get an access token

Choose one setting in Bash. If your workspace checks OAuth scopes, request the read scope:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
SCOPE_ARGS=(--data-urlencode 'scope=query_engine.clusters:read')
```

If your admin confirmed that workspace permissions are active for management API requests, omit the optional scope:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
SCOPE_ARGS=()
```

Set your workspace URL and client ID, then run the request in the same terminal. Curl prompts for the client secret without displaying it.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
WORKSPACE_URL='https://your-workspace.example'
CLIENT_ID='your-client-id'

set +x
unset ACCESS_TOKEN
TOKEN_REPLY=$(curl --proto '=https' --silent --show-error --fail-with-body \
  --user "$CLIENT_ID" \
  --data 'grant_type=client_credentials' \
  "${SCOPE_ARGS[@]}" \
  "$WORKSPACE_URL/oauth2/token") &&
  ACCESS_TOKEN=$(jq -er '.access_token | strings | select(length > 0)' <<< "$TOKEN_REPLY") &&
  jq '{token_type, expires_in, scope}' <<< "$TOKEN_REPLY"
```

A successful `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:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "access_token": "<redacted>",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "query_engine.clusters:read"
}
```

`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 the `Authorization` 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.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --proto '=https' --silent --show-error --fail-with-body \
    --header @- "$WORKSPACE_URL/api/v1/queryservices" \
    <<< "Authorization: Bearer $ACCESS_TOKEN"
```

HTTP `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:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"total": 0, "items": []}
```

When you finish the example, run `unset ACCESS_TOKEN TOKEN_REPLY`.

For request fields and responses, see [Get an app access token](https://docs.e6data.com/api-reference/workspace-oauth-2-0/post-oauth2-token.md) or [List clusters](https://docs.e6data.com/api-reference/workspace/get-api-v1-queryservices.md). To check the state of one cluster, use [Get a cluster](https://docs.e6data.com/api-reference/workspace/get-api-v1-queryservices-name.md) with the same token. To verify a grant to one cluster, follow [Check which clusters a job can read](https://docs.e6data.com/platform/automate/manage-oauth-clients.md#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](#1-get-an-access-token). 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 its `expires_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](https://docs.e6data.com/platform/automate/manage-oauth-clients.md#rotate-a-secret-while-jobs-keep-running).

## Troubleshoot a request

| Where you got stuck | What to do |
| - | - |
| Token request returns `401 invalid_client` | Check that the client ID and current secret belong to the same workspace URL. Ask the admin to confirm the client is enabled. |
| Token request returns `400 invalid_scope` | For scope-based access, check the requested scope against the client's assigned scopes. If workspace permissions are active, omit the management scope and request a fresh token. |
| List request returns `401` | Check the workspace URL and bearer header. If the token expired, get a new one and retry the list request. |
| List request returns `403` | For scope-based access, check the returned scope. For active workspace permissions, ask the admin to check the client's permission to list clusters. For a named cluster, check its grant and any access inherited from groups. |

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](https://docs.e6data.com/query/connect/rest-api-for-sql.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.