- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 09:16 AM
I need to obtain a list of my Databricks workflows with their job IDs in a notebook Databricks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 10:08 AM
@VabethRamirez - Please find the below code snippet. Kindly modify according to your needs.
import requests, json
# Set the Databricks API URL. <eg. dbi.databricks.cloud.com>
api_url = 'https://<URL>/api/2.1'
# Set the Databricks token
token = '<API token>'
# Get a list of all jobs
jobs_endpoint = f"{api_url}/jobs/list"
headers = {
'Authorization': f"Bearer {token}",
'Content-Type': 'application/json'
}
response = requests.get(jobs_endpoint, headers=headers)
if response.status_code == 200:
# Extract the list of jobs
jobs = response.json()['jobs']
# Print the job names and IDs
for job in jobs:
print(f"Job ID: {job['job_id']}, Job Name: {job['settings']['name']}")
else:
print(f"Failed to retrieve jobs. Status Code: {response.status_code}")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 09:58 AM
Can you check if this post answers you question: https://community.databricks.com/t5/community-discussions/reading-workflow-items/td-p/61277
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 10:08 AM
@VabethRamirez - Please find the below code snippet. Kindly modify according to your needs.
import requests, json
# Set the Databricks API URL. <eg. dbi.databricks.cloud.com>
api_url = 'https://<URL>/api/2.1'
# Set the Databricks token
token = '<API token>'
# Get a list of all jobs
jobs_endpoint = f"{api_url}/jobs/list"
headers = {
'Authorization': f"Bearer {token}",
'Content-Type': 'application/json'
}
response = requests.get(jobs_endpoint, headers=headers)
if response.status_code == 200:
# Extract the list of jobs
jobs = response.json()['jobs']
# Print the job names and IDs
for job in jobs:
print(f"Job ID: {job['job_id']}, Job Name: {job['settings']['name']}")
else:
print(f"Failed to retrieve jobs. Status Code: {response.status_code}")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 10:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 10:33 AM
Thank you for sharing!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 07:17 AM
Hi @VabethRamirez ,
Also, instead of using directly the API, you can use databricks Python sdk :
%pip install databricks-sdk --upgrade
dbutils.library.restartPython()
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
job_list = w.jobs.list(expand_tasks=False)
Additional examples : https://github.com/databricks/databricks-sdk-py/tree/main/examples