cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How obtain a list of workflows in Databricks?

VabethRamirez
New Contributor II

I need to obtain a list of my Databricks workflows with their job IDs in a notebook Databricks

1 ACCEPTED SOLUTION

Accepted Solutions

shan_chandra
Databricks Employee
Databricks Employee

@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}")

 

View solution in original post

5 REPLIES 5

Lakshay
Databricks Employee
Databricks Employee

shan_chandra
Databricks Employee
Databricks Employee

@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}")

 

VabethRamirez
New Contributor II
I managed to solve it with this solution
# Importar la biblioteca de Databricks
from databricks_api import DatabricksAPI
# Configurar el token de acceso a la API de Databricks
token = "<token>"
host = "<url_your_databricks_host>"

 

# Crear una instancia de la API de Databricks
db = DatabricksAPI(host=host, token=token)

 

# Obtener una lista de todos los workflows en Databricks
jobs_list = jobs['jobs']

 

# Iterar sobre los trabajos y obtener informaciรณn detallada, incluyendo Job ID
for job in jobs_list:
    job_id = job['job_id']
    job_name = job['settings']['name']
    print(f"Job Name: {job_name}, Job ID: {job_id}")






 

Thank you for sharing!

artsheiko
Databricks Employee
Databricks Employee

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 

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