cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

404 on GET Billing usage data (API)

vdeorios
New Contributor II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

cristianmolina
New Contributor III

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.

View solution in original post

4 REPLIES 4

cristianmolina
New Contributor III

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.

Yes! That works, thank you 😀

@vdeorios @cristianmolina  can anyone of you please post the full code here

jose_gonzalez
Moderator
Moderator

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.

Join 100K+ Data Experts: Register Now & Grow with Us!

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!