I'm trying to follow the steps documented here:
https://learn.microsoft.com/en-us/rest/api/azure/devops/artifactspackagetypes/nuget/update-package-version?view=azure-devops-rest-7.1&source=docs
For using version 7.1 of the REST API to remove a view from a package in an artifact feed. I'm doing this in Poweshell. I used a GET to:
https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}/packages?$top=1000&api-version=7.1&includeAllVersions=true
To get a list of all versions of all packages (well, the first 1000, but it only returns 44), so that much of the uri with those ids appears to work fine. I'm filtering the results, then copying the package and version ids directly out of the results of the above query:
$thisPackage = $allVersionsResponse.value | Where-Object { $_.Name -eq $package.Name };
$removeViewVersions = $thisPackage.versions | Where-Object { $_.views.name -eq $ReleaseNumber -and ! $_.isLatest };
foreach ($version in $removeViewVersions) {
$patchUrl = "$pkgsBaseUrl/nuget/packages/$($thisPackage.name)/versions/$($version.id)?api-version=7.1";
$viewId = $version.views | where-object { $_.name -contains $ReleaseNumber } | select-object -First 1 -ExpandProperty "id";
$body = @"
{
"op": "remove",
"path": "/views/-",
"value": "$viewId"
}
"@
$patchUrl; $body; Invoke-RestMethod -Uri $patchUrl -Method Patch -Headers $headers -Body $body
}
At each stage I can confirm that I'm getting the ids returned from the initial query - so presumably correct - into the appropriate variables and inserting them into my $patchUrl:
https://pkgs.dev.azure.com/{organisation name}/{project id}/_apis/packaging/Feeds/{feed name}/nuget/packages/{package name}/versions/{version id}?api-version=7.1
, which then looks exactly like the one in the doco, give-or take the names I've used for the placeholders:
PATCH https://pkgs.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}/nuget/packages/{packageName}/versions/{packageVersion}?api-version=7.1
All I get back is:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Cannot find the file {packagename}.36330163.0.0-b9b6-4afa-89fb-faaf325d272e.nupkg in package '{packagename} {versionid}' in feed '{feedid}'","typeName":"Microsoft.VisualStudio.Services.Packaging.Shared.WebApi.Exceptions.PackageNotFoundException,
Microsoft.VisualStudio.Services.Packaging.Shared.WebApi","typeKey":"PackageNotFoundException","errorCode":0,"eventId":3
000}
At line:12 char:19
+ ... Url; $body; Invoke-RestMethod -Uri $patchUrl -Method Patch -Headers $ ...
I'm assuming the ids are portable between the feeds.dev.avure.com and pkgs.dev.azure.com interfaces, but I couldn't find any way in the documentations to make changes in feeds, or list the available versions in pkgs.
Thanks for any suggestions.