Upstream Service Error when using MusicDataRequest

Hey there!

I'm trying to use MusicDataRequest to fetch the contents of a user's library.

Most of the documented endpoints I've tried seem to be working as expected, but the /me/library/artists and /me/library/albums endpoints are consistenty giving me a 500 Upstream Service Error.

Here's an example of my code, and the resulting error:

let url = URL(string: "https://api.music.apple.com/v1/me/library/albums")!
let request = MusicDataRequest(urlRequest: URLRequest(url: url))
do {
    let response = try await request.response()
    let string = String(data: response.data, encoding: .utf8)!
    print("success: \(string)")
} catch {
    print("error: \(error)")
}
MusicDataRequest.Error(
   status: 500,
   code: 50001,
   title: "Upstream Service Error",
   detailText: "Error fetching library content",
   id: "5OFXMJAGNU2WCTDKNAYYP4BJXI",
   originalResponse: MusicDataResponse(
      data: 153 bytes,
      urlResponse: <NSHTTPURLResponse: 0x0000000280f04dc0>
   )
)

If I replace /albums with /songs or /playlists in the above code everything works as expected. Is there something I'm missing from the albums and artists requests? Or is this a bug with the API?

Replies

Hello @benzgrant,

Thank you very much for your feedback. It's great that you printed the entire error, because that allowed us to get more information about the root cause of this failure.

Our server API team is currently investigating the issue.

Best regards,

Hi @JoeKun,

Thanks for the response the other week. Do you know if the API team got anywhere with their investigation? I'm still seeing 500 errors when I hit the /me/library/artists and /me/library/albums endpoints.

I've also noticed a couple of other strange things which I think might be related...

Firstly, when I use the Apple Music web player (https://music.apple.com) I see An error occurred when I try to view my Artists or Albums (although I'm still able to view my Songs and Playlists as expected). I've attached some screenshots to demonstrate:

Secondly, when I fetch songs from the /me/library/songs endpoint I'm seeing a discrepancy in the number of songs returned. In the response JSON I see "meta":{"total":1773}, but when I page through 100 songs at a time I'm getting less than 100 songs per page, and I'm ending up with a total of just 1721 songs. I've included some console logs to demonstrate:

fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=0, data.count: 98, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=100, data.count: 95, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=200, data.count: 99, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=300, data.count: 100, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=400, data.count: 96, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=500, data.count: 98, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=600, data.count: 94, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=700, data.count: 100, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=800, data.count: 96, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=900, data.count: 98, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1000, data.count: 98, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1100, data.count: 97, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1200, data.count: 96, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1300, data.count: 98, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1400, data.count: 97, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1500, data.count: 97, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1600, data.count: 97, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1700, data.count: 67, meta.total: 1773
fetchSongs url: https://api.music.apple.com/v1/me/library/songs?limit=100&offset=1800, data.count: 0, meta.total: 1773
fetchSongs fetched: 1721

I suspect that these issues might be related, I'm not sure if this is a general issue with the API or if it's specific to my account (I'm a solo dev and I haven't had the chance to test with another account yet). Any help or advice would be really appreciated!!

I have the EXACT same issue with my own account. Interested to see if this goes anywhere...

This seems to have still not be resolved. Has there been any progress at all on this issue?

Hello @jtc42,

If you are still experiencing these issues, it would be helpful to us if you could gather the debug description of the MusicDataRequest.Error being thrown.

There is some information in that error that should help us investigate the root cause of the bad server response.

Thank you very much in advance for your help.

Best regards,

  • Hi @JoeKun,

    The only information I get back from the error is

    { "errors": [ { "id": "QPYHSMMBQU2MSHVNUADDCRUP5M", "title": "Upstream Service Error", "detail": "Error fetching library content", "status": "500", "code": "50001" } ] }

    returned when fetching the list of albums in the users library.

    This seems to be really account-specific. It occurs on my personal account, but seems to be really uncommon.

Add a Comment

Worth adding too that just like @benzgrant I get the same error using the official web player, and it also occurs when loading the list of library artists, but not songs or playlists.

Requesting the library artists returns

{
    "errors": [
        {
            "id": "OVBAPGJPXEC6DUKGRJSEHIFG3Q",
            "title": "Upstream Service Error",
            "detail": "Error fetching library content",
            "status": "500",
            "code": "50001"
        }
    ]
}

Interestingly I checked this again last week, and for my account both the web player and the endpoints have finally started working!

  • Oh strange... I wonder if it's a regional rollout of a backend update? I'm in the UK and still getting the exact same issue. Unless you did something to your library I can't see why this would be the case... Curious.

Add a Comment

Hello @jtc42,

Thank you for letting us know about these specific errors.

There was a server-side issue with data linked to your specific account. We have made a server-side change that should address the errors you were encountering.

Would you mind testing that again?

I hope this helps.

Best regards,

  • @JoeKun Works perfectly now, thank you! Can I ask what the change was, in case I encounter this again (other users etc)? Might help others get the fix quicker if I can let them know the cause. Thanks

  • Hi @jtc42,

    As I said before, there was a server-side issue with data linked to your specific account.

    We believe the root cause of this issue has been addressed so it shouldn't happen to any new users, but for those already affected by this issue, we can fix the data linked to specific accounts, like we did for yours.

    For the time being, reaching out again on the developer forums, like you did in this thread, including the specific error you get from Apple Music API, might be the most expeditious way to address the issue for a specific user.

    Best regards,

Add a Comment

I'm also getting this error:

{
  "errors": [
    {
      "id": "KX7SPPFCOEATR42NHSDWMRAHT4",
      "title": "Upstream Service Error",
      "detail": "Service failure: Cloud Library",
      "status": "500",
      "code": "50001"
    }
  ]
}

It happens when I save a playlist to the POST https://api.music.apple.com/v1/me/library/playlists endpoint. The playlist seems to save fine to my library, so it seems odd that I'm getting this error.

I'm getting a similar issue when I trying to add a track to one of my playlists.

Failed to perform MusicDataRequest.Context( url: "https://api.music.apple.com/v1/me/library/playlists/p.8Wx63rZTVm1RAxY/tracks", currentRetryCounts: [.other: 1] ) with MusicDataRequest.Error( status: 500, code: 50001, title: "Upstream Service Error", detailText: "Unable to update tracks", id: "LE36LDFW4BHXYHU3GGQPSF563Y", originalResponse: MusicDataResponse( data: 146 bytes, urlResponse: <NSHTTPURLResponse: 0x0000000282a63640> ) ).

Hello @JoeKun my team is also seeing similar issues.

We are doing a POST on the following endpoint: https://api.music.apple.com/v1/me/library/playlists/%s/tracks with the following as the payload:

{ "data": [{"id": track_id, "type": "song"}, ....] }

I am seeing an internal server error Internal Server Error: Upstream Service Error-Unable to update tracks

and here is the full response content: {"errors":[{"id":"BEVQOFCT3F2OM3I7NBLJKAFI54","title":"Upstream Service Error","detail":"Unable to update tracks","status":"500","code":"50001"}]}

I think you can leverage the error ID to check on your end?

Could you help check on your end if the account that we are attempting to update the playlist is having the same data issue that other people on this thread was seeing?