cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to use Databricks REST API within a notebook without providing tokens

brickster_2018
Databricks Employee
Databricks Employee
 
1 ACCEPTED SOLUTION

Accepted Solutions

brickster_2018
Databricks Employee
Databricks Employee

Disclaimer: This code snippet uses an internal API. It's not recommended to use internal API's in your application as they are subject to change or discontinuity.

%python
import requests
 
API_URL = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().getOrElse(None)
TOKEN = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().getOrElse(None)
 
response = requests.get(
  API_URL + '/api/2.0/clusters/list',
  headers={"Authorization": "Bearer " + TOKEN},
)
 
if response.status_code == 200:
  print [c['cluster_id'] for c in response.json()['clusters']]
else:
  print("Error: %s: %s" % (response.json()["error_code"], response.json()["message"]))

View solution in original post

1 REPLY 1

brickster_2018
Databricks Employee
Databricks Employee

Disclaimer: This code snippet uses an internal API. It's not recommended to use internal API's in your application as they are subject to change or discontinuity.

%python
import requests
 
API_URL = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().getOrElse(None)
TOKEN = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().getOrElse(None)
 
response = requests.get(
  API_URL + '/api/2.0/clusters/list',
  headers={"Authorization": "Bearer " + TOKEN},
)
 
if response.status_code == 200:
  print [c['cluster_id'] for c in response.json()['clusters']]
else:
  print("Error: %s: %s" % (response.json()["error_code"], response.json()["message"]))

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now