cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Databricks Rest API

Ramya
New Contributor III

Hi, I am having an issue accessing data bricks API 2.0/workspace/mkdirs through python. I am using the below azure method to generate the access token. I am not sure why I am getting 404 any suggestions?

token_credential = DefaultAzureCredential()

scope = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default".

Below is the snippet of my code.

response = requests.post(

 url="https://databricksurl/api/2.0/workspace/mkdir",

 headers={ 'Authorization': "Bearer " + access_token,

      'Accept': 'application/json'},

 json = {'path' : '/user/test'}

)

print(json.dumps(json.loads(response.text), indent = 2))

print(response)

Error:

{

 "error_code": "ENDPOINT_NOT_FOUND",

 "message": "No API found for 'POST /workspace/mkdir'"

}

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

6 REPLIES 6

Kaniz
Community Manager
Community Manager

Hi @Ramya Natarajan​, The Databricks REST API allows for programmatic management of various Databricks resources. This article provides links to the latest version of each API.

Important

To access Databricks REST APIs, you must authenticate.

Also, this community thread had a similar discussion. Please go through it and let us know if this helps. Thanks.

Ramya
New Contributor III

@Kaniz Fatma​ I checked that community thread and it didn't help. I am using https://docs.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/app-aad-token to create an access token through that I am trying to access this 2.0/workspace/mkdir to create a folder in data bricks which is not working. Any suggestions?

Thanks

PCR
New Contributor II

issue is with data/json...

try the below -

from azure.identity import DefaultAzureCredential

import requests

default_scope = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default"

credential = DefaultAzureCredential()

token = credential.get_token(default_scope)

access_token = str(token.token)

url="https://adb-xxxxx.azuredatabricks.net/api/2.0/workspace/mkdirs"

headers={"Authorization":"Bearer "+access_token, "Content-Type": "application/x-www-form-urlencoded"}

response = requests.post(

 url=url,

 headers=headers,

 data = '{"path":"/dpaas-ids2/test"}'

)

print(response)

Ramya
New Contributor III

Yes that is correct!. It worked. Thanks

Kaniz
Community Manager
Community Manager

Hi @Ramya Natarajan​, Awesome! I'm glad you found a solution. Would you like to mark an answer as the best for the community?

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.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.