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