cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

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

User16869510359
Esteemed Contributor
 
1 ACCEPTED SOLUTION

Accepted Solutions

User16869510359
Esteemed Contributor

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

User16869510359
Esteemed Contributor

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"]))

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.