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.
Excited to expand your horizons with us? Click here to Register and begin your journey to success!
Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!