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 can I make Databricks API calls from notebook?

User16752245312
Databricks Employee
Databricks Employee

Access to Databricks APIs require the user to authenticate. This usually means creating a PAT (Personal Access Token) token. Conveniently, a token is readily available to you when you are using a Databricks notebook.

databricksURL = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiUrl().getOrElse(None)
myToken = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().getOrElse(None)

Thus you don't need to generate and manage a token yourself.

import requests
 
header = {'Authorization': 'Bearer {}'.format(myToken)}
endpoint = '/api/2.0/jobs/runs/list'
payload = """{"limit": "5", "offset": "0"}"""
 
resp = requests.get(
  databricksURL + endpoint,
  data=payload,
  headers=header
)

3 REPLIES 3

519320
New Contributor II

hmmm.... no resolution yet? 

StephanieAlba
Databricks Employee
Databricks Employee

This was a question and answer in one

Panda
Valued Contributor

@User16752245312  You can use Databricks Secret Scope to manage sensitive data such as personal access tokens (PATs) securely. Storing your token in a secret scope ensures you donโ€™t hard-code credentials in your notebook, making it more secure.
For more details how to use Databricks REST API

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group