Sub topic 16
Workspace-level versus account-level APIs
This chapter assumes you can authenticate the CLI (OAuth or a personal access token), use profiles, and send a bearer-authenticated REST request. Here you learn that Databricks exposes two API surfaces, and that calls fail when you send them to the wrong one.
Two surfaces, two hosts
Databricks separates what lives inside one workspace from what spans your whole organization.
- Workspace-level APIs manage objects in a single workspace: jobs, clusters, notebooks, SQL warehouses, and secrets. The host is the workspace URL, such as
https://<workspace-host>. - Account-level APIs manage objects shared across workspaces: the workspaces themselves, account users and groups, service principals, Unity Catalog metastores and their assignments, and usage and billing settings. The host is the account console,
https://accounts.cloud.databricks.comon AWS.
Account-level paths include your account ID, for example /api/2.0/accounts/<account-id>/workspaces. Workspace-level paths do not.
Choosing the right host in the CLI
The CLI picks the surface from the profile's host. An account-level profile also needs an account_id. This is a sketch of two profiles in ~/.databrickscfg:
[dev-workspace]
host = https://<workspace-host>
[my-account]
host = https://accounts.cloud.databricks.com
account_id = <account-id>Log in to each one with databricks auth login, passing the matching --host and, for the account profile, --account-id. After that, account commands live under the databricks account group, while workspace commands sit at the top level:
# Workspace-level: jobs in one workspace
databricks jobs list --profile dev-workspace --output json
# Account-level: all workspaces in the account
databricks account workspaces list --profile my-account --output json
# Account-level: groups defined for the whole account
databricks account groups list --profile my-account --output jsonCalling account APIs over REST
The mechanics match workspace calls. Only the host and path change, and the token must belong to a principal that has account permissions.
curl -sS "https://accounts.cloud.databricks.com/api/2.0/accounts/$DATABRICKS_ACCOUNT_ID/workspaces" \
-H "Authorization: Bearer $DATABRICKS_TOKEN"A personal access token is created inside one workspace, so it generally does not authorize account-level calls. For account automation, use OAuth: either a user login or a service principal with an OAuth secret (machine-to-machine).
Using the SDK
The Python SDK has two separate clients. Using the wrong one is a common source of confusing errors.
from databricks.sdk import AccountClient, WorkspaceClient
w = WorkspaceClient(profile="dev-workspace")
a = AccountClient(profile="my-account")
print([j.settings.name for j in w.jobs.list()])
print([ws.workspace_name for ws in a.workspaces.list()])Common errors
| Symptom | Likely cause |
|---|---|
| 404 or "no such endpoint" on an account path | The request went to a workspace host |
| 401 or 403 on an account call | Token is a workspace PAT, or the principal lacks account admin rights |
| `databricks account` command asks for an account ID | The profile has no `account_id` |
| Workspace command fails with an account profile | The profile's host is the account console |
Exercise
A script uses a personal access token from one workspace to call GET /api/2.0/accounts/<account-id>/workspaces on the account console host, and gets an authorization error. Give two reasons this can happen and one fix.
Show answer
The token is a workspace-scoped personal access token, which does not authenticate to the account console, and the principal may also lack account admin permissions. The fix is to authenticate with OAuth (a user login, or a service principal with an OAuth secret) that has been granted account-level access, and send the request to the account host.