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

How can I make Databricks API calls from notebook?

User16752245312
New Contributor III

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
)

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @ User15926069072995960181 ! My name is Kaniz, and I'm the technical moderator here. Great to meet you, and thanks for your question! Let's see if your peers on the Forum have an answer to your questions first. Or else I will follow up shortly with a response.

519320
New Contributor II

hmmm.... no resolution yet?