Skip to content

Conversation

@colmilloestelar
Copy link

#I add manually a folder named "test"
$ReportPortalUri = 'ServerURL/reports'
Write-Host "Upload an item..."

$uploadItemPath = 'C:\test\test.rdl' # single File
$catalogItemsUri = $ReportPortalUri + "/api/v2.0/CatalogItems"
$bytes = [System.IO.File]::ReadAllBytes($uploadItemPath)

$payload = @{
"@odata.type" = "#Model.Report";
"Content" = [System.Convert]::ToBase64String($bytes);
"ContentType"="";
"Name" = 'newNameOfthefile';
"Path" = '/folterToSave';
} | ConvertTo-Json

Invoke-WebRequest -Uri $catalogItemsUri -Method Post -Body $payload -ContentType "application/json" -UseDefaultCredentials | Out-Null

#----------------------------
#Download example working
$ReportPortalUri = 'URLserver/reports'
Write-Host "Download an item..."

$downloadPath = 'C:\download\example.rdl'
$catalogItemsApi = $ReportPortalUri + "/api/v2.0/CatalogItems(Path='/test/example')/Content/$value" #You need to put exact route to avoid error Code = 0.

$url = [string]::Format($catalogItemsApi, $item)
$response = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials
[System.IO.File]::WriteAllBytes($downloadPath, $response.Content)
#----------------------
#delete.
$ReportPortalUri = 'ServerUrl/reports'

Write-Host "Delete an item..."

$url = $ReportPortalUri + "/api/v2.0/CatalogItems(Path='/test')" #this will delete the full folder
Invoke-WebRequest -Uri $url -Method Delete -UseDefaultCredentials | Out-Null

#I add manually a folder named "test"
$ReportPortalUri = 'ServerURL/reports'
Write-Host "Upload an item..."

$uploadItemPath = 'C:\test\test.rdl' # single File
$catalogItemsUri = $ReportPortalUri + "/api/v2.0/CatalogItems"
$bytes = [System.IO.File]::ReadAllBytes($uploadItemPath)

$payload = @{
    "@odata.type" = "#Model.Report";
    "Content" = [System.Convert]::ToBase64String($bytes);
    "ContentType"="";
    "Name" = 'newNameOfthefile';
    "Path" = '/folterToSave';
    } | ConvertTo-Json

Invoke-WebRequest -Uri $catalogItemsUri -Method Post -Body $payload -ContentType "application/json" -UseDefaultCredentials | Out-Null

#----------------------------
#Download example working
$ReportPortalUri = 'URLserver/reports'
Write-Host "Download an item..."

$downloadPath = 'C:\download\example.rdl' 
$catalogItemsApi = $ReportPortalUri + "/api/v2.0/CatalogItems(Path='/test/example')/Content/$value" #You need to put exact route to avoid error.

$url = [string]::Format($catalogItemsApi, $item)
$response = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials
[System.IO.File]::WriteAllBytes($downloadPath, $response.Content)
#----------------------
#delete.
$ReportPortalUri = 'ServerUrl/reports'

Write-Host "Delete an item..."

$url = $ReportPortalUri + "/api/v2.0/CatalogItems(Path='/test')" #this will delete the full folder
Invoke-WebRequest -Uri $url -Method Delete -UseDefaultCredentials | Out-Null
@jtarquino
Copy link
Member

The PR only shows a rename of the file

@colmilloestelar
Copy link
Author

Path='/folder/file'
your code throws an error, the cause is you only write the folder. Anyway, I can't download files or folders correctly, I always get 0-byte files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants