Getting information about ID of the Azure Databricks workspace is not so obvious.
There is no information about it in the API specification: https://docs.databricks.com/api/latest/workspace.html
That’s probably because this property is not related to the content of the workspace 🙂 That’s right! Raw JSON responses are intended to deliver different set of content in a different scope. On the other hand, I personally think that this should be in official API! Nevertheless…
So what contains workspace details? Turns out the answer is simple: HEADER of your any request response 🙂
Just execute your request, it could be any kind, like folder listing.
Then get the content of the headers in your REST response. Look for the X-Databricks-Org-Id key. It will simply represent your Workspace ID that you’re looking for 🙂
Try it with this example based on a command that lists folders in a root path:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$DBAPIRootUrl = "your_api_url_that_depends_on_a_location" # example: https://uksouth.azuredatabricks.net $DBAPIKey = "your_api_token" # Example dapi601e67891a9d1f7886e40916479aaa [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 $ClustersAPIListUrl = $DBAPIRootUrl.Trim('/') + "/api/2.0/workspace/list" $headers = @{ Authorization = "Bearer $DBAPIKey" "Content-Type" = "application/json" } $Path= "/" $parameters = @{ path = $Path } $response = Invoke-WebRequest -Uri $ClustersAPIListUrl -Method GET -Headers $headers -Body $parameters $response.Headers.'X-Databricks-Org-Id' |
Output: