我尝试使用 databricks API 列出我的用户下的内容。以下是我的代码
`if (-not (Get-PackageProvider -ListAvailable -Name NuGet)) {
Install-PackageProvider nuget -Scope CurrentUser -Force
}
if (-not (Get-Module -ListAvailable -Name azure.databricks.cicd.tools)) {
Install-Module -Name azure.databricks.cicd.tools -Scope CurrentUser -Force
}
Import-Module -Name azure.databricks.cicd.tools
Function Format-BearerToken ($BearerToken) {
Return "Bearer $BearerToken"
}
try {
# Attempt to connect to Databricks
Connect-Databricks -BearerToken $ADB_Token -Region $region
# List the content of the user folder
# Assuming the user folder is "/Users/your.username" - replace with your actual user path
$userFolderPath = "/Users/[email protected]/" # Replace with your actual Databricks user folder path
# Create the body as a hashtable (note the difference in creating a hashtable)
$body = @{
path = $userFolderPath
}
# Debug: Check the Body that will be sent
$BodyText = $body | ConvertTo-Json -Depth 10
Write-Output "Request Body: $BodyText"
# Test the connection by making an API call to list the workspace contents in your user folder
$workspaceContent = Invoke-DatabricksAPI -BearerToken $ADB_Token -Region $region `
-Method GET -API "workspace/list" -Body $BodyText
# Output the content
$workspaceContent
}
catch {
Write-Error "An error occurred: $_"
}`
我的路径参数输出如下所示
Request Body: {
"path": "/Users/[email protected]/"
}
但我得到了错误
发生错误:无法处理参数“Body”的参数转换。无法将“{"path": "/Users/ [email protected] /"}“System.String”类型的值转换为“System.Collections.Hashtable”类型。
我也尝试过没有 $BodyText = $body | ConvertTo-Json -Depth 10
,在这种情况下,我得到了erro code 404 - 404 RESOURCE_DOES_NOT_EXIST Operation was performed on a resource that does not exist.
我的用户名是正确的,并且我确实在其下有一个 test.py 文件。
我有两个问题:
- 我如何列出内容?2)由于我无法列出内容,我想如果授权成功,但其他情况下我首先会得到
401 UNAUTHORIZED The request does not have valid authentication credentials for the operation.
- 这是正确的吗?
根据此文档,主体应为类型
Hashtable
例子:
@{clusterId="abc-123";name="bob"}
并且您给出的类型也不存在
String
api,而是使用。workspace/list
/api/2.0/workspace/list
接下来,
path
应该在参数中而不是在正文中给出。使用下面的代码。
输出: