PowerShell / PowerShellGallery

228 stars 65 forks source link

Can't request JSON response with API calls to /api/v2 #21

Closed chris48s closed 5 years ago

chris48s commented 6 years ago

Hi. We rely on the powershell gallery API on https://shields.io/ to generate badges which are used by many popular powershell gallery projects. Since the recent updates to powershell gallery, we are now unable to request data from the API in JSON format - it seems the content negotiation header is no longer respected. For example, if I call

$ curl -H "Accept: application/atom+json,application/json" "https://www.powershellgallery.com/api/v2/Packages()?$filter=Id%20eq%20'ACMESharp'%20and%20IsLatestVersion%20eq%20true"

this now unexpectedly returns an XML response. This means none of our powershell gallery badges will render because the code that generates them expects JSON and fails to parse the XML response. Examples:

Do we now need to pass a different header, or is this a bug? It would be great if we could get these fixed for our mutual users.

ghost commented 6 years ago

Sorry for the issue, Chris48s, we are working on it. That problem is the core of the issue which broke our connection to the Automation Gallery (see https://github.com/PowerShell/PowerShellGallery/blob/master/psgallery_status.md#powershell-gallery-status) We don't have an ETA for a fix yet, but it is something we are working to address.

As a TEMPORARY WORKAROUND, try using https://msconfiggallery.cloudapp.net/api/v2/ instead.
This is not a URL that will last indefinitely, but it will be available for the duration of this issue, which will take until early next week. That's the URL we have hooked up to solve the Automation Gallery integration problem. We will update this issue, and the Gallery Status page, before we remove that URL.

chris48s commented 6 years ago

Thanks for responding @JKeithB :+1: I'l check in on this next week

edyoung commented 6 years ago

@Chris48s, how much of a problem would it be for you to request and parse XML instead of JSON? Reason I ask is that all the primary clients of the PowerShell Gallery (like PowerShellGet) currently use XML so that gets a lot more testing and verification. cc @rebro-msft

chris48s commented 6 years ago

Hi @edyoung

We're a community-driven project and rely on contributions from volunteers. I'll give a quick summary of what would be involved:

At the moment we've got some shared code for parsing feeds from services which build on NuGet package manager/gallery. We've got a one for NuGet V2 currently shared by the integrations for PowerShell Gallery, Chocolatey and ReSharper Gallery and another one for NuGet V3 shared by the NuGet and MyGet badges. All of it assumes the response is JSON and everything other than PowerShell Gallery currently works, although the code is not so elegant. If we need to switch to XML for PowerShell Gallery, I'd be inclined to treat PowerShell as a special case at first rather than try to migrate mutliple services at once.

In order to do that, we'd need a BasePowerShellGalleryService class, which extends BaseXmlService and then 2 further classes PowerShellGalleryDownloads (for the downloads badge) and PowerShellGalleryVersion (for the version badge) each extending BasePowerShellGalleryService. The closest badge family to crib from as an example would be the eclipse marketplace badges. We use fast-xml-parser for XML processing. We do have at least have a good test suite for PowerShell Gallery, which would make things easier.

If you are interested in submitting a pull request to help us switch us to the XML API, feel free to follow up and ask more questions - we're happy to work with new contributors. Cheers.

mithrandyr commented 5 years ago

Any update on this issue? been over 2 weeks -- all my PowerShell Module repos (on GitHub) rely on the Shields.io service and I really would like for the badges to start working again. Also, some of MS own repos on GitHub also rely on this service and their shields aren't working either (showing "invalid") -- https://github.com/Azure/azure-powershell

paulmelnikow commented 5 years ago

The JSON API seems sometimes unresponsive now, though the XML one is working. Seems like we should switch Shields over to using the XML endpoint. Does that make sense from your end @edyoung?

chris48s commented 5 years ago

Just as an update on this, we've switched our code to use the XML outputs so this no longer affects us. It is possible there may be other users affected by this issue. Happy if you want to close the issue.

edyoung commented 5 years ago

Hi Chris, sorry we broke the json version of this API, and really appreciate the work you've done to update shields.io.

JustinGrote commented 1 year ago

For anyone coming to this, to close the loop, the json was never fixed, and XML along with v2 (no v3 support) is still the only option, at least as far as I can tell.