08-16-2023 11:04 AM
I'm trying to get my billing usage data from Databricks API (documentation: https://docs.databricks.com/api/gcp/account/billableusage/download) but I keep getting an 404 error.
Code:
import requests
import json
token = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get()
api_url = f"{my_domain_url}/api/2.0/accounts/{my_account_id}/usage/download"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
params = {
"start_month": "2023-06",
"end_month": "2023-07"
}
response = requests.get(api_url, headers=headers, params=params)
if response.status_code == 200:
cost_data_csv = response.content.decode('utf-8')
print("Usage logs downloaded successfully.")
else:
print("Error:", response.status_code, response.text)
Error: 404 {"error":"Bad Target: /api/2.0/accounts/<my_account_id>/usage/download"}
Note: I've already attempted modifying the URL prefix from /api/2.0 to /api/2.1 and have also thoroughly verified the accuracy of both my account ID and domain URL.
09-12-2023 08:32 AM
Since this is an endpoint under the account section and not under workspace, you have to use the Databricks account login URL (https://accounts.cloud.databricks.com) instead of your domain url. Also, you must use basic authentication with user and password, the bearer token is not allowed here. I had the same problem as you, hope this helps.
09-12-2023 08:32 AM
Since this is an endpoint under the account section and not under workspace, you have to use the Databricks account login URL (https://accounts.cloud.databricks.com) instead of your domain url. Also, you must use basic authentication with user and password, the bearer token is not allowed here. I had the same problem as you, hope this helps.
09-13-2023 09:53 AM
Yes! That works, thank you 😀
03-10-2024 07:00 AM
@vdeorios @cristianmolina can anyone of you please post the full code here
09-12-2023 09:46 AM
HIi @vdeorios ,
Just a friendly follow-up. Did any of the responses help you to resolve your question? if it did, please mark it as best. Otherwise, please let us know if you still need help.
09-26-2024 07:38 AM
Bumping this to see if there is a solution. Per Databricks basic authentication is no longer allowed. I am unable to authenticate to get access to this endpoint (401 error). Does anyone have a solution to querying this endpoint?
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group