Visual Studio Team Services Package Management API

707 Views Asked by At

So, much research has shown that the only way to push a NuGet package to the VSTS Package Management is with the CLI tools vs the NuGet Package Explorer app. So, I'm hoping to fix that to make life easier.

Initial research makes me think that I can use one of the REST APIs that Microsoft offers. When I use the link below in Postman, I get the response back that would normally be the Microsoft login page, which is what I would expect when I'm not passing any authentication in the GET request.

https://fabrikam.feeds.visualstudio.com/DefaultCollection/_apis/packaging/feeds/EngineeringInternal/packages?api-version=2.0-preview

However, when I replace the demo account and feed name with my own, I get a 401 error.

https://sartainsoftwaresolutions.feeds.visualstudio.com/DefaultCollection/_apis/packaging/feeds/SartainSoftware.Common/packages?api-version=2.0-preview

Unless I have to enable access to the given API in my VSTS account, I'm not sure what I'm missing.

Any thoughts?

1

There are 1 best solutions below

5
starian chen-MSFT On

First, regarding 401 issue, you need to specify alternate authentication credential (Profile >Security > Alternate authentication credentials) or Personal access token (user name is empty, do not need to specify), you can’t use email account directly (e.g. xxx.hotmail.com)

Secondly, to push a NuGet Package, you can use this REST API:

Put https://[account].pkgs.visualstudio.com/_packaging/[feed id]/nuget/v2/

Simple steps for Postman:

  1. Using Get feeds/Get a feed REST API to get feed id
  2. Type above push package REST API URL and change request method to PUT
  3. Click Authorization tab
  4. Choose Basic Auth
  5. Leave Username to blank and type Personal Access Token to Password box
  6. Click Headers tab and add a new item (key: X-NuGet-ApiKey; value:VSTS)
  7. Click Body tab
  8. Choose form-data option
  9. Add a new Item: Select File option in Key box and click choose files button to select a nupkg file
  10. Click Send button and the response status result will be 202.

Regarding login page issue, it won't redirect to login page if current user is not authenticated when call REST API. You can authorize access to REST APIs with OAuth.