If you are building an automated pipeline or integration with Chocolatey, you might want to query their repository to list packages programmatically. While the Chocolatey documentation focuses heavily on CLI commands or downloading specific packages, it uses a standard NuGet v2 OData feed under the hood. This means you can leverage standard OData query parameters to list, filter, and paginate through packages.

The Core Endpoint

The base endpoint for querying packages from the Chocolatey Community Repository is:

https://community.chocolatey.org/api/v2/Packages

However, because the repository hosts tens of thousands of packages, querying this endpoint without any parameters can result in a timeout or an overwhelming payload. To get a clean, functional list, you must use OData system query options like $top, $filter, and $orderby.

How to List the Latest Packages

To retrieve the latest 20 packages published to Chocolatey, you can filter for the latest versions and order them by their publication date in descending order. Here is the URL structure:

https://community.chocolatey.org/api/v2/Packages()?$filter=IsLatestVersion eq true&$orderby=Published desc&$top=20

Breaking Down the Query Parameters:

  • $filter=IsLatestVersion eq true: Ensures you only get the latest stable version of each package, filtering out older versions. Use IsAbsoluteLatestVersion eq true if you also want to include pre-release versions.
  • $orderby=Published desc: Sorts the packages by the date they were published, starting with the newest.
  • $top=20: Limits the response to the first 20 records (ideal for performance and pagination).

PowerShell Implementation Example

Since you are building a PowerShell pipeline, here is a practical script using Invoke-RestMethod to fetch and parse the packages into a clean PowerShell object:

# Define the API endpoint with OData parameters
$uri = "https://community.chocolatey.org/api/v2/Packages()?`$filter=IsLatestVersion eq true&`$orderby=Published desc&`$top=20"

# Fetch the XML feed
$response = Invoke-RestMethod -Uri $uri -Method Get

# Parse and output the package details
$response | Select-Object Title, Version, Published, Summary | Format-Table -AutoSize

Note: In PowerShell double-quoted strings, the dollar sign ($) is used for variable expansion. Be sure to escape the OData dollar signs with a backtick (`$) as shown above, or use single quotes for the URL string.

Handling Pagination

If you need to fetch more than 20 packages, you can implement pagination using the $skip parameter. For example, to get the next 20 packages (packages 21-40), append &$skip=20 to your query:

https://community.chocolatey.org/api/v2/Packages()?$filter=IsLatestVersion eq true&$orderby=Published desc&$top=20&$skip=20
```