08-14-2025 06:00 AM
Goodday,
I have an Azure DevOps pipeline with which I provision our Databricks workspaces. With this pipeline I also create the catalogs through the Databricks API (/api/2.1/unity-catalog/catalogs).
Create a catalog | Catalogs API | REST API reference | Azure Databricks
I also want to add a tag to the catalog, but i cannot figure out how to do this through this or another REST API.
Is this possible?
Kind regards,
Marco
08-14-2025 08:31 AM
Thanks szymon_dybczak,
I have solved it with the "/api/2.0/sql/statements/" REST API
param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)] [System.String] $FullDatabricksName,
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)] [System.String] $ResourceGroupName
)
Function DatabricksConfig
{
param(
[string]$Method,
[string]$API,
[string]$Body = "",
[string]$FullDatabricksName,
[boolean]$AccountConsole = $false
)
If ($AccountConsole -eq $true)
{
$Url = $Url = "https://accounts.azuredatabricks.net"+$API
}
Else
{
$Databricks_Workspace_Url = (Get-AzDatabricksWorkspace -Name $FullDatabricksName -ResourceGroupName $ResourceGroupName).Url
$Url = "https://"+$Databricks_Workspace_Url+$API
}
#Authentication header
$azureApiToken = (ConvertFrom-SecureString (Get-AzAccessToken -Resource "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" -AsSecureString).Token -AsPlainText)# "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" represents the programmatic ID for Azure Databricks along with the default scope (/.default, URL-encoded as %2f.default).
$authHeader = @{
"Authorization"="Bearer " + "$azureApiToken";
"Content-Type"="application/json";
}
If ($Body -eq "")
{
$Result = Invoke-RestMethod -Method $Method -Uri $Url -Headers $authHeader -ErrorAction SilentlyContinue
}
Else
{
$Result = Invoke-RestMethod -Method $Method -Uri $Url -Headers $authHeader -Body $Body -ErrorAction SilentlyContinue
}
Return $Result
}
$WarehouseId = ((DatabricksConfig -Method "Get" -API "/api/2.0/sql/warehouses" -FullDatabricksName $FullDatabricksName).warehouses | Where-Object name -eq "Serverless Starter Warehouse").id
$Body = Get-Content "./GetCatalogProps/SQL.json" | ConvertFrom-JSON
$Body.statement = "ALTER CATALOG curated SET TAGS ('tag1' = 'val1');"
$Body.warehouse_id = $WarehouseId
$Body = $Body | ConvertTo-JSON
DatabricksConfig -Body $Body -Method "Post" -API "/api/2.0/sql/statements/" -FullDatabricksName $FullDatabricksName
Regards,
Marco
08-14-2025 06:35 AM
Hi @Marco37 ,
Unfortunately, I believe this is not currently possible through REST API. The only options you have are via UI or using SQL.
Unfortunately, it's also no possible to do this using terraform. There's a PR that is hanging from some time, but still no progress.
https://github.com/databricks/terraform-provider-databricks/pull/3268
08-14-2025 08:31 AM
Thanks szymon_dybczak,
I have solved it with the "/api/2.0/sql/statements/" REST API
param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)] [System.String] $FullDatabricksName,
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$false)] [System.String] $ResourceGroupName
)
Function DatabricksConfig
{
param(
[string]$Method,
[string]$API,
[string]$Body = "",
[string]$FullDatabricksName,
[boolean]$AccountConsole = $false
)
If ($AccountConsole -eq $true)
{
$Url = $Url = "https://accounts.azuredatabricks.net"+$API
}
Else
{
$Databricks_Workspace_Url = (Get-AzDatabricksWorkspace -Name $FullDatabricksName -ResourceGroupName $ResourceGroupName).Url
$Url = "https://"+$Databricks_Workspace_Url+$API
}
#Authentication header
$azureApiToken = (ConvertFrom-SecureString (Get-AzAccessToken -Resource "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" -AsSecureString).Token -AsPlainText)# "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" represents the programmatic ID for Azure Databricks along with the default scope (/.default, URL-encoded as %2f.default).
$authHeader = @{
"Authorization"="Bearer " + "$azureApiToken";
"Content-Type"="application/json";
}
If ($Body -eq "")
{
$Result = Invoke-RestMethod -Method $Method -Uri $Url -Headers $authHeader -ErrorAction SilentlyContinue
}
Else
{
$Result = Invoke-RestMethod -Method $Method -Uri $Url -Headers $authHeader -Body $Body -ErrorAction SilentlyContinue
}
Return $Result
}
$WarehouseId = ((DatabricksConfig -Method "Get" -API "/api/2.0/sql/warehouses" -FullDatabricksName $FullDatabricksName).warehouses | Where-Object name -eq "Serverless Starter Warehouse").id
$Body = Get-Content "./GetCatalogProps/SQL.json" | ConvertFrom-JSON
$Body.statement = "ALTER CATALOG curated SET TAGS ('tag1' = 'val1');"
$Body.warehouse_id = $WarehouseId
$Body = $Body | ConvertTo-JSON
DatabricksConfig -Body $Body -Method "Post" -API "/api/2.0/sql/statements/" -FullDatabricksName $FullDatabricksName
Regards,
Marco
08-14-2025 09:43 AM
Hi @Marco37 ,
Thanks for sharing solution. Could you mark your solution as a best answer? This helps others with similar question find correct answer faster.
Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!
Sign Up Now