musickit js albums undefined for user

I am trying to get the list of albums from a user's library. I use this code. The user is able to successfully login but the albums property of the library object is undefined. How do I get the list of albums for a user?

music.authorize().then(function() { music.api.library.albums.then(function(cloudAlbums) { // user's cloudAlbums console.log('cloudAlbums'); }); });

Hi, there @ebitar2006

You’re correct that the music.api.library.albums method should be able to return a list of the user’s iCloud Library albums. Per our documentation:

If no ids are passed, this method fetches all the library albums in alphabetical order.

In the code example you provided, music.api.library.albums should be invoked as a function, which will return a Promise that is “then-able”. Also your console.log statement is logging the string "cloudAlbums" and not the argument itself.

Here is the full example with those changes:

music.authorize().then(function() {
  music.api.library.albums().then(function(cloudAlbums) {
    // user's cloudAlbums
    console.log('cloudAlbums', cloudAlbums);
  });
});

Your code example may have been copied from the example in our documentation here: https://developer.apple.com/documentation/musickitjs

These docs appear to be incorrect. I’ll follow up on getting them corrected with the same change.

musickit js albums undefined for user
 
 
Q