Databricks REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 05:58 AM
Hi , I am trying to create a Global Initscript using rest API as below successfully in the first step using Powershell. In the second step I am trying to enable it using rest api and getting the following error: Any guidance or help is appreciated.
STEP 1:
# Set variables
param([string]$databricksWorkspaceUrl, [string]$token, [string]$scriptName)
$databricksWorkspaceUrl = databricksWorkspaceUrl
$token = $token
$scriptName = $scriptName$scriptContent = Get-Content -Path "scriptfile.sh" -Raw
$scriptContent
$uri = "$databricksWorkspaceUrl/api/2.0/global-init-scripts"
$headers = @{
"Authorization" = "Bearer $token"
}
$base64Content = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($scriptContent ))
# Construct the request body JSON
$requestBody = @{
name = $scriptName
script = $base64Content
} | ConvertTo-Json
$requestBody
$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $requestBody -ContentType "text/plain"
Write-Output $response
STEP 2:
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Error 401 Unauthorized HTTP ERROR 401 Problem accessing /api/2.0/workspace-conf. Reason: Unauthorized
I have checked with the URL and Token and successful in connecting to the workspace from prompt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 08:26 PM
This API use PATH method, but you use POST
PATCH /api/2.0/workspace-confhttps://docs.databricks.com/api/workspace/workspaceconf/setstatus