I've finally been spending some time getting to know the MusicKit API, which is really nicely designed and will let me get rid of a ton of less efficient code as I start implementing it.
I'm used to hitting the /artists/{id}/view/latest-release API endpoint via a URLSession data task to return an artist's most recent release, if available. I see that it seems to be possible to return that information in a MusicCatalogResourceRequest, but the following code returns nil for me:
var request = MusicCatalogResourceRequest<Artist>.init(matching: \.id, equalTo: "35719")
request.properties = [.latestRelease]
do {
let response = try await request.response()
print(response.items.first?.latestRelease)
} catch {
print(error.localizedDescription)
}
In the code above, I've hardcoded the ID for an artist, but I've tried this in a for loop and it returns nil for every artist in my library. (By contrast, when adding .fullAlbums or .albums to the properties array, it does fetch that relationship).
When I construct a MusicDataRequest against the endpoint I'm used to hitting, it correctly returns the latest release. This is the code I'm using for that:
let request = MusicDataRequest(urlRequest: URLRequest(url: URL(string: "https://api.music.apple.com/v1/catalog/us/artists/\(artist)/view/latest-release")!))
do {
let response = try await request.response()
let decoded = try JSONDecoder().decode(AlbumReponse.self, from: response.data)
print(decoded)
} catch {
print("error getting latest release: \(error.localizedDescription)")
}
Is this a bug, or am I doing something incorrect? I didn't file a Feedback yet in case this was an error on my end, but if it's a bug I'm happy to put one in. Thanks!
Hello @talking small,
You're doing everything right, and this is an issue I can easily reproduce.
Please do file a ticket on Feedback Assistant about this issue.
Thank you very much in advance for your help.
Best regards,