MusicKit playlist creation fails when number of songs is too large

I'm creating a playlist using the MusicKit endpoint and its failing with a generic error when I give it too many songs.

[DataRequesting] Failed to perform MusicDataRequest.Context(
 url: "https://api.music.apple.com/v1/me/library/playlists",
 currentRetryCounts: [.other: 1]
) with MusicDataRequest.Error(
 status: 500,
 code: 50001,
 title: "Upstream Service Error",
 detailText: "Service failure: Cloud Library",
 id: "NX5X43DEV3KH5NEK3Q7CEHJENM",
 originalResponse: MusicDataResponse(
  data: 153 bytes,
  urlResponse: <NSHTTPURLResponse: 0x0000000280220080>
 )
).

I tried setting a maximum of 500 songs and the request succeeded. Is there a known limit to how many songs can be added at once?

Replies

I’m seeing this too: the call arbitrarily blows-up when saving larger playlists. There doesn’t seem to be a specific upper limit - sometimes 3,000 tracks will fail, other times 6,000 tracks will work fine. Suspect it depends on server loads (fyi 500 is a gateway error).

It wouldn’t be so bad if you could break the call up and add to a playlist chunk by chunk but the “new” MusicKit call to add to a playlist is completely unusable as it seems to map to the old (comically slow) MPMediaPlaylist.addItem method.

The other interesting thing you will find is that if you read the playlist tracks immediately after creating a new playlist, there aren’t any. They come along a few seconds later. So much for async/await. Worse still, if there’s a failure between when the call apparently “succeeded” and when the tracks subsequently appear, it’s completely silent. You just end up with a playlist with no tracks.

I get the impression that Apple are not eating what they cook when it comes to MusicKit.

And incidentally all of the above issues have been reported by me via Feedback Assistant for months without so much as an acknowledgement.

  • Thanks. My workaround for now is to create a playlist (0 songs added) then add tracks in 250 count chunks. On each add request I attempt it up to 4 times with exponential backoff. If it fails after 4 times I move on to the next chunk and abandon those songs. Extremely slow and ridiculous that it has to be done. For my case the ux will be bearable in most cases, but this is still crazy. The Spotify api has none of these problems

  • Thanks for your response. I have another question here if you're familiar with this issue https://developer.apple.com/forums/thread/723527

Add a Comment