API Browse and paging

I hope this is the right place for this. I can’t get my head around paging for browse requests. For example, for the artist David Bowie (with limit = 100), the ‘release-count’ returned is 2004. How do these numbers relate? Is the count 2004 the number of results in the response I have already received or is it the total and I have only received 100 (or thereabouts). Do I have to get 100 twenty-one times (i.e. 2100) to get everything? I’m not getting this at all.

It’s the total number of release, you can confirm this when searching on the site:

To get all of them you need to paginate:

Browse requests are the only requests which support paging: any browse request supports an ‘offset=’ argument to get more results. Browse requests also support ‘limit=’: the default limit is 25, and you can increase that up to 100.

Special note for releases: To ensure requests can complete without timing out, we limit the number of releases returned such that the entire list contains no more than 500 tracks. (However, at least one full release is always returned, even if it has more than 500 tracks; we don’t return “partial” releases.) This means that you may not get 100 releases per page if you set limit=100; in fact the number will vary per page depending on the size of the releases. In order to page through the results properly, increment offset by the number of releases you get from each response, rather than the (larger, fixed) limit size.

2 Likes

I assume you are doing a request similar to

https://musicbrainz.org/ws/2/release/?artist=5441c29d-3602-4898-b1a1-b77fa23b8e50&inc=aliases&limit=100&offset=0

Yes, the count returned is the total number of results. limit is the number of results to return in one request, where 100 is the maximum. offset is how many items to skip from the results.

So to get all results you would start with offset=0 and increase the offset by 100 (or whatever limit you have set), so you do requests with offset=100, offset=200 etc. until you got the full results.

3 Likes

Great, thank you. That makes sense.

Depending on the search you need, it may work or it may not work, because of an old pagination bug.

1 Like