Hi community,
I was reading the Databricks API documentation and I want to get information about one job if this is schedule with the status PAUSED or UNPAUSED. I was watching that there is this api call: https://docs.databricks.com/api/workspace/jobs/get
I tried to make the code for it and testing it:
def _get_single_job_api_call(self):
"""Get single job information through Databricks API call"""
headers = {
'Authorization': f'Bearer {self.access_token}',
'Content-Type': 'application/json'
}
try:
response = requests.get(
url = f'{self.workspace_host}/api/2.2/jobs/get',
json = {'job_id': self.job_id},
headers = headers
)
response.raise_for_status() # Raises HTTPError for bad responses (4xx and 5xx)
return response.json()
except requests.exceptions.Timeout:
logger.error("Request timed out.")
except requests.exceptions.ConnectionError:
logger.error("Failed to connect to the server.")
except requests.exceptions.HTTPError as e:
logger.error(f"HTTP error occurred: {e}")
except requests.exceptions.RequestException as e:
logger.error(f"Request failed: {e}")
except Exception as e:
logger.error(f"Unexpected error: {e}")
return None
def is_job_scheduled(self):
get_job_status = self._get_single_job_api_call()
schedule_job_status = get_job_status['settings']['schedule']['pause_status']
if not get_job_status:
logger.error("Failed to retrieve job status.")
return True # Safeguard by assuming it's scheduled
try:
schedule_job_status = get_job_status['settings']['schedule']['pause_status']
return schedule_job_status != 'UNPAUSED' # True if PAUSED or any other value, False only if explicitly UNPAUSED
except KeyError:
logger.error("Job schedule information is missing. Assuming job is scheduled for safety.")
return True # Safeguard by assuming it's scheduled
But, I'm receiving errors like: HTTP error occurred: 403 Client Error: Forbidden for url: <workspace_host>/api/2.2/jobs/get
with this error message inside:
{"error_code":401,"message":"Credential was not sent or was of an unsupported type for this API."}
how can I solve it, I'm making the api call wrong?