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?