MusicKit MusicCatalogSearchRequest.response() starting failing with 401 userTokenRequestFailed for users without subscription

Hello,

I have an app published on AppStore which relies on MusicKit's functionality to retrieve results of MusicCatalogSearchRequest even when a user doesn't have an Apple Music subscription. (As per other sources and this thread, this is expected to work normally for users without the subscription.)

The app used to work fine for months, yet today all the devices I tested on failed to execute the request (both AppStore and dev versions), resulting in the following log:

2023-07-27 23:45:16.036271+0200 Lisyn[6288:3156868] [DataRequesting] Updated user token cache with new error.
2023-07-27 23:45:16.043294+0200 Lisyn[6288:3156868] [DataRequesting] Failed retrieving user token: Error Domain=ICError Code=-8101 "Failed to fetch music user token with Unauthorized (401) status code. Account does not have an active Apple Music Subscription." UserInfo={NSDebugDescription=Failed to fetch music user token with Unauthorized (401) status code. Account does not have an active Apple Music Subscription.}. Throwing .userTokenRequestFailed.
2023-07-27 23:45:16.043413+0200 Lisyn[6288:3156868] [DataRequesting] Failed refreshing user token for MusicDataRequest.Context(
  url: "https://api.music.apple.com/v1/catalog/it/search?term=B&l=en-GB&types=songs&limit=25&omit%5Bresource%5D=autos",
  currentRetryCounts: [.userTokenInvalid: 1],
  activeRetryContext: RetryContext(
    reason: .userTokenInvalid,
    previousTokens: .personalizedTokens(
      developerToken: "some token",
      userToken: "some other token"
    )
  )
). Error = .userTokenRequestFailed.

I am using automatic token generation and make requests via MusicKit:

func searchMusic(searchText: String) async throws -> [PlaybackStoreID] {
        return try await throttler.schedule {
            var request = MusicCatalogSearchRequest(term: searchText, types: [Song.self])
            request.limit = 25
            return try await request.response().songs.map(\.id.rawValue)
        }
    }

None of the certificate/identifier settings, nor the code related to the issue has been touched between when it was working and now. Also, live versions stopped working as well, so I am sure this isn't related.

Is this a temporary issue? Should I roll out a fix using non-automatic token generation?

Thank you!

Answered by myra5hik in 760357022

For those having the same issue: Apple Music web API would return results normally with requests having solely the developer token in their bearer.

Accepted Answer

For those having the same issue: Apple Music web API would return results normally with requests having solely the developer token in their bearer.

MusicKit MusicCatalogSearchRequest.response() starting failing with 401 userTokenRequestFailed for users without subscription
 
 
Q