Search code examples
chocolatey

Get list of Chocolatey packages using API


Is there a way to use the OData api on the chocolatey.org site to obtain a list of all packages available in the community repo?

What I've tried:

I can see using the $metadata service that Packages is exposed:

https://chocolatey.org/api/v2/$metadata

From this I can use something like this to get the first "page" of XML:

http://chocolatey.org/api/v2/Packages()?$skip=0

The website limits to 40 "entries" by default I think, so the $skip can be altered accordingly.

(Another way is to use the $skipToken which points to the next "page").

All versions seem to return in the responses. It would be irresponsible to write a loop to effectively download the database. I don't think the site owners would appreciate this. I'm not planning to do this regularly.

Reasons for doing this aside, is there a better way to get the package list using only the API, not via the choco CLI?

Update 1 Getting warmer using filters - clue in the metadata eg. https://chocolatey.org/api/v2/Packages()?$filter=IsLatestVersion This now returns latest versions only at least.


Solution

  • You could use something like Fiddler to inspect the traffic going from the Chocolatey CLI. Issuing choco search git reveals the following request:

    GET /api/v2/Search()?$filter=IsLatestVersion&$skip=0&$top=30&searchTerm='git'&targetFramework=''&includePrerelease=false HTTP/1.1
    

    Please note that you shouldn't be using their API without contacting them first. Even if it's just for personal use. They have no public documentation for their APIs, and so it should be treated as an internal resource.