Apple Music API fetch more than 10 recently played songs

Using this recently played resources API , I get up to 10 resources that were recently played.
However I want as many recently played resources as I can, so I tried using the limit=(int) query parameter, as described in the official document.
However, it's not working.
Using the limit=(int) query parameter for 10 (or below) songs is working :
Code Block
https://api.music.apple.com/v1/me/recent/played?limit=10


but anything above 10 is not:
Code Block
https://api.music.apple.com/v1/me/recent/played?limit=15

or
Code Block
https://api.music.apple.com/v1/me/recent/played?limit=20


How can I get more than 10 resources?

Hey @swiftymoon, I have the same issue. I was looking to get recently-played tracks from Apple Music.

I used Spotify before, which returns up to 50 recently played tracks, so was disappointed with Apple Music API.

I look a bit deeper into this.

TL;DR:


This endpoint supports offset, so you can reach resources beyond the 10 resources limit by setting the right offset.

Update 1:


The endpoint yields at most 50 most recently played resources.

So with the limit of 10, using offset values 0, 10, 20, 30, and 40 will give you all recently played resources you can access.



Observation 1: If you set limit above 10, you get an error in the payload.


This confirms we have to operate in the range of 1-10 resources per request.

Code Block json
{
"errors": [
{
"id": "X6VOUROLIVE5XJSVKIA5FFHQEI",
"title": "Invalid Parameter Value",
"detail": "Value must be an integer less than or equal to 10",
"status": "400",
"code": "40005",
"source": {
"parameter": "limit"
}
}
]
}


Just out of curiosity, limit that's less than 1 (so 0 and including negatives) also throws.

Observation 2: offset DOES work for this endpoint


Other endpoints accept offset query param, so I tried I here too. Good news, offset works!

Endpoints and results I've got:

I had just 4 entries in recently played. That was expected, today was the first time I've used Apple Music.

Code Block
https://api.music.apple.com/v1/me/recent/played




When I set the limit=2, I got just 2 entries. As expected.

Code Block
https://api.music.apple.com/v1/me/recent/played?limit=2




Then I tried to get "next page", so limit=2&offset=2. And lo and behold, I got the next page!

Code Block
https://api.music.apple.com/v1/me/recent/played?limit=2&offset=2




Then I also looked at what happens if you set offset beyond what's in the recently-played list. As expected, I got empty array.

Code Block
https://api.music.apple.com/v1/me/recent/played?offset=10



The offset can be set to as high as 1000000000s (10^9). At 10000000000 (one more zero), the query param is ignored.

Negative offset is ignored.



Conclusion:

  1. You can only get between 1-10 recently-played resources.

  2. You can use offset to get resources beyond the 10 items limit.

  3. The question remains about how many recently-played resources are made available in total. E.g. Spotify keeps only the last 50 tracks. Anything older than that and you're out of luck. How many are available via Apple Music API? See Update 1 - you can get max 50 recently played resources.


Docs at the time of writing:

Apple Music API Docs: https://developer.apple.com/documentation/applemusicapi/get_recently_played_resources
Spotify API Docs: https://developer dot spotify dot com/documentation/web-api/reference/#endpoint-get-the-users-currently-playing-track
Apple Music API fetch more than 10 recently played songs
 
 
Q