Estou tentando listar o conteúdo sob meu usuário usando a API do databricks. Abaixo está meu código
`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: $_"
}`
minha saída do parâmetro de caminho se parece com isso
Request Body: {
"path": "/Users/[email protected]/"
}
Mas eu recebo o erro
Ocorreu um erro: Não é possível processar a transformação de argumento no parâmetro 'Body'. Não é possível converter o valor do tipo "{"path": "/Users/ [email protected] /"} "System.String" para o tipo "System.Collections.Hashtable".
Eu também tentei sem $BodyText = $body | ConvertTo-Json -Depth 10
e nesse caso eu obtive oerro code 404 - 404 RESOURCE_DOES_NOT_EXIST Operation was performed on a resource that does not exist.
Meu nome de usuário está correto e tenho o arquivo test.py abaixo dele.
Tenho duas perguntas:
- como posso listar o conteúdo? 2)Como não consegui listar o conteúdo, acho que se a autorização foi bem-sucedida, caso contrário, primeiro eu teria obtido
401 UNAUTHORIZED The request does not have valid authentication credentials for the operation.
- isso está correto?
de acordo com esta documentação o corpo deve ser do tipo
Hashtable
exemplo:
@{clusterId="abc-123";name="bob"}
e você está dando
String
o tipo também a APIworkspace/list
não existe em vez disso use/api/2.0/workspace/list
.Em seguida, o
path
deve ser fornecido no parâmetro, não no corpo.Use o código abaixo.
Saída: