Reputation: 77
This is a sample REST API uri to retrieve logs from the AzureDevOps Release.
https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/logs?api-version=4.1-preview.2
The Verb is GET and content type is "application/zip"
How do i retrieve the zip file through a REST API call through powershell using Invoke-RestMethod
?
If i pass Out-File
to this command and save it as zip, it doesn't convert the binary output of the API response to zip.
How do i do it ?
Upvotes: 4
Views: 7164
Reputation: 30392
You need to name the output as zip.
Below Powershell script works for me:
Param(
[string]$collectionUrl = "https://vsrm.dev.azure.com/{organization}",
[string]$project = "0522TFVCScrum",
[string]$releaseid = "35",
[string]$filename = "D:\temp\ReleaseLogs_$releaseid.zip",
[string]$user = "username",
[string]$token = "password/PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uri = "$collectionUrl/$project/_apis/Release/releases/$releaseid/logs"
Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/zip" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -OutFile $filename
Upvotes: 6