Is it possible to get an artistId from MusicKit just off the albumID

struct AlbumDetails : Hashable {

    let artistId: String?
}

func fetchAlbumDetails(upc: String) async throws -> AlbumDetails {
    let request = MusicCatalogResourceRequest<Album>(matching: \.upc, equalTo: upc)
    let response = try await request.response()

    guard let album = response.items.first else {
        throw NSError(domain: "AlbumNotFound", code: 0, userInfo: nil)
    }
    
    
    do {
        let artistID = try await fetchAlbumDetails(upc: upc)
        print("Artist ID: \(artistID)")
    } catch {
        print("Error fetching artist ID: \(error)")
    }


    return AlbumDetails(artistId: album.artists?.first?.id)  

with this function, i can return nearly everything except the artist ID so i know its not a problem with the request but I know there has to be a way to get the artistID, there has too. If anyone has a solution to this I would reallly appricate it

Replies

I don't see artisID anywhere in the Album or Song API. Albums have an artistName property, which can consist of zero or more artist names, concatenated. Same thing for the artistName on a Song. Physical albums might have multiple artists, with different artists for each song. Since MusicKit is an API, and not a relational database, it does not seem to expose the artist IDs, just the names. You might need to parse the artistName fields and perform searches on the names to retrieve their IDs -- admittedly not an optimal solution.