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

5 REPLIES 5

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
Databricks Employee
Databricks Employee

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.

Dave_Nithio
Contributor

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?

Connect with Databricks Users in Your Area

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