Search code examples
statisticsnugetodata

Nuget.org OData feed returns different results than website


I'm writing a small utility to retrieve meta data and download counts from the nuget.org OData feed (https://nuget.org/api/v2). When looking at the results of the OData feed they are less (sometimes significantly so) than what is shown on an individual package's nuget.org page. This is true both for the VersionDownloadCount and DownloadCount properties.

Unfortunately, aside from a blog post, there is very little documentation about nuget.org's OData feed.

Really I'm trying to get detailed download stats from somewhere, without resorting to screen-scraping, but not finding much for an api outside of the core package management endpoints.

Does anyone have alternative methods of accessing nugget package download numbers?


Solution

  • The download data on nuget.org seems to be from a NuGet v3 service and not the older NuGet v2 service. Why the download numbers are different between the two is a question for the NuGet team.

    If you look at the NuGet v3 search API:

    https://api-v3search-0.nuget.org/query

    You can see the figures match more closely what is shown on nuget.org. I did see some small differences when looking at Newtonsoft.Json but looking now they seem to be identical, so maybe there is some caching going on so they are not quite in sync.

    So you probably want to look at using the NuGet v3 endpoints instead.

    There are various NuGet v3 NuGet packages that should allow you to call the API for v3. Calling the API using the NuGet v3 NuGet packages seems to be more complicated than it was with NuGet v2 so I cannot tell you how to use it to get the results you want using the NuGet v3 client API.

    You can query the search API directly using query parameters similar to what the NuGet v2 OData feed used. For example you can search for Newtonsoft.Json using:

    https://api-v3search-0.nuget.org/query?q=id:newtonsoft.json

    This does not return just Newtonsoft.Json information but other matches. I was hoping the id part would filter things better, which it does, but it does not exclude other package id matches. You can also use skip and take to page through the data.

    So you could just call the NuGet v3 search API and read the raw json data, which might be simpler than using the NuGet v3 client API.