1

Using Apple Music API I was able to get all artists in my library:

func getArtists(forToken musicUserToken: String) {
    var urlComponents = URLComponents()
    urlComponents.scheme = "https"
    urlComponents.host = "api.music.apple.com"
    urlComponents.path = "/v1/me/library/artists"

    var request = URLRequest(url: urlComponents.url!)
    request.setValue("Bearer (developerToken)", forHTTPHeaderField: "Authorization")
    request.setValue(musicUserToken, forHTTPHeaderField: "Music-User-Token")

    let dataTask = URLSession.shared.dataTask(with: request) { (data, urlResponse, error) in
        ...
    }
    dataTask.resume()
}

For example, the code above returns this JSON:

{
    "data":[
        {
            "attributes":{
                "name":"Anne-Marie"
            },
            "href":"/v1/me/library/artists/r.wb9aRPu",
            "id":"r.wb9aRPu",
            "type":"library-artists"
        },
        {
            "attributes":{
                "name":"Bruno Mars"
            },
            "href":"/v1/me/library/artists/r.zCrRBIw",
            "id":"r.zCrRBIw",
            "type":"library-artists"
        },
        ...
    ]
}

But, it seems to me that each object refers to an artist in my library and not the artist in the Apple Music Library. Because if I get the artist id and try to get this artist albums, nothing is found. For example, a GET to the URL https://api.music.apple.com/v1/catalog/us/artists/r.wb9aRPu returns an error:

{
    "errors":[
        {
            "id":"GJXVG3NROYGJPDRECZLCPYKLEQ",
            "title":"Internal Service Error",
            "status":"500",
            "code":"50000"
        }
    ]
}

But if I do the same GET for the artist ID 178834 (which I got from an example on Apple's website), it returns the correct response:

{
    "data":[
        {
            "id":"178834",
            "type":"artists",
            "href":"/v1/catalog/us/artists/178834",
            "attributes":{
                "name":"Bruce Springsteen",
                "genreNames":[
                    "Rock"
                ],
                "url":"https://itunes.apple.com/us/artist/bruce-springsteen/178834"
            },
            "relationships":{
                "albums":{
                    "data":[
                        {
                            "id":"1136909069",
                            "type":"albums",
                            "href":"/v1/catalog/us/albums/1136909069"
                        },
                        {
                            "id":"1134170183",
                            "type":"albums",
                            "href":"/v1/catalog/us/albums/1134170183"
                        },
                        ...
                    ],
                    "href":"/v1/catalog/us/artists/178834/albums",
                    "next":"/v1/catalog/us/artists/178834/albums?offset=144"
                }
            }
        }
    ]
}

What I want to do is to get all albums from all artists that a user has in his library. But I cannot do this with the artist ID that /me/library/artists returns. So, is there another way to get the artist ID for the artists that the user has in the library?

Marcos Tanaka
  • 3,112
  • 3
  • 25
  • 41
  • 1
    I have a similar issue [here](https://stackoverflow.com/questions/50786400/musickitjs-cant-play-songs-from-users-library) where I can only play songs with an ID from catalog and not library. So if anyone knows a way to get catalog id's to match up with library id's I think that could solve both our issues. – rycirese Jun 11 '18 at 15:54
  • 1
    Also on Apple Developer Forums: https://forums.developer.apple.com/thread/104182 – Marcos Tanaka Jun 11 '18 at 20:01

0 Answers0