โ06-07-2022 09:31 AM
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'"
}
โ07-29-2022 11:14 AM
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.
โ06-08-2022 03:44 AM
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.
โ06-08-2022 08:47 AM
@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
โ06-10-2022 03:50 PM
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)
โ06-13-2022 03:19 PM
Yes that is correct!. It worked. Thanks
โ06-13-2022 08:36 PM
Hi @Ramya Natarajanโ, Awesome! I'm glad you found a solution. Would you like to mark an answer as the best for the community?
โ07-29-2022 11:14 AM
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 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.