DEV Community

Avelyn Hyunjeong Choi
Avelyn Hyunjeong Choi

Posted on

Databricks API

NOTE
In the example, whenever the user creates a new entity, it creates a new PAT. In order to create/list/delete the PAT, it needs two following tokens for the service principal: Azure Active Directory(AD) token and Azure Active Directory management endpoint token.

Requirement - The service principal requires the Contributor or Owner role on the Databricks workspace in Azure.

Step 1 - Get Azure AD token for the service principal

https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/service-prin-aad-token#--get-an-azure-ad-access-token-with-the-azure-cli

**NOTE - You can get tenant_id, client_id, and client_secrect from your service principal as below.

Image description

Image description

POST https://login.microsoftonline.com//oauth2/v2.0/token

Image description

Image description

Step 2 - Get Azure AD management endpoint token

POST https://login.microsoftonline.com//oauth2/token

Image description

Now you have two Azure AD tokens (one with Databricks service principal from step1 and another with AD management endpoint from step2)

Step 3 - Create Personal Access Token based on two AD tokens from previous steps

POST /api/2.0/token/create \
-H 'Authorization: Bearer ' \
-H 'X-Databricks-Azure-SP-Management-Token: ' \
-H 'X-Databricks-Azure-Workspace-Resource-Id: /subscriptions//resourceGroups//providers/Microsoft.Databricks/workspaces/'

Image description

Image description

You can now retrieve token_value as well as token_id from above API call. These values will be used to create an external location, catalog and schema and delete PAT that has been already used.

Optionally, you can put request body as below.

Image description

https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/tokens

You can run any Databricks REST API call. Below link provides the REST API endpoint available with Azure Databricks
https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay