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.
This endpoint supports offset, so you can reach resources beyond the 10 resources limit by setting the right offset.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.
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.
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.
You can only get between 1-10 recently-played resources.
You can use offset to get resources beyond the 10 items limit.
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_resourcesSpotify API Docs: https://developer dot spotify dot com/documentation/web-api/reference/#endpoint-get-the-users-currently-playing-track