Share via

PackageNotFoundException from Azure REST API

MOSER Rob 20 Reputation points
2025-09-10T03:55:58.47+00:00

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.

Azure DevOps
0 comments No comments

Answer accepted by question author

Rakesh Mishra 9,675 Reputation points Microsoft External Staff Moderator
2025-09-10T18:35:04.3333333+00:00

Hi MOSER Rob,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

In patchUrl, you are using $version.id

$patchUrl = "$pkgsBaseUrl/nuget/packages/$($thisPackage.name)/versions/$($version.id)?api-version=7.1";

But in document, packageVersion is needed as an input parameter. The API is expecting the display version as highlighted in screenshot below.

Here is the updated patchUrl.

$pkgNameEnc = [System.Web.HttpUtility]::UrlEncode($thisPackage.name)
$pkgVersionEnc = [System.Web.HttpUtility]::UrlEncode($version.version)   # use 'version', not 'id'
$patchUrl = "$pkgsBaseUrl/nuget/packages/$pkgNameEnc/versions/$pkgVersionEnc?api-version=7.1"

User's image

User's image

Please let me know how this goes.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.