Documentation for the Spotify Web API Node.JS wrapper

Check the GitHub repository for more information about the project

getTrack

method
this.getTrack()
  • @param: {string}trackIdThe track's ID.
  • @param: {Object}[options]The possible options, currently only market.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getTrack('3Qm86XLflmIXVm1wcwkgDK').then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing information about the track. Not returned if a callback is given.

Description

Look up a track.

Source

this.getTrack = function(trackId, options, callback) {
     // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function') {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = {};
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    var request = WebApiRequest.builder()
      .withPath('/v1/tracks/' + trackId)
      .withQueryParameters(actualOptions)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (actualCallback) {
      promise.then(function(data) {
        actualCallback(null, data);
      }, function(err) {
        actualCallback(err);
      });
    } else {
      return promise;
    }
  };

getTracks

method
this.getTracks()
  • @param: {string[]}trackIdsThe IDs of the artists.
  • @param: {Object}[options]The possible options, currently only market.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getArtists(['0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing information about the artists. Not returned if a callback is given.

Description

Look up several tracks.

Source

this.getTracks = function(trackIds, options, callback) {
    // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function') {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = {};
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    var request = WebApiRequest.builder()
      .withPath('/v1/tracks')
      .withQueryParameters({
        'ids' : trackIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, actualOptions);

    var promise = _performRequest(HttpManager.get, request);

    if (actualCallback) {
      promise.then(function(data) {
        actualCallback(null, data);
      }, function(err) {
        actualCallback(err);
      });
    } else {
      return promise;
    }
  };

getAlbum

method
this.getAlbum()
  • @param: {string}albumIdThe album's ID.
  • @param: {Object}[options]The possible options, currently only market.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getAlbum('0sNOF9WDwhWunNAHPD3Baj').then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing information about the album. Not returned if a callback is given.

Description

Look up an album.

Source

this.getAlbum = function(albumId, options, callback) {
    // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function') {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = {};
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    var request = WebApiRequest.builder()
      .withPath('/v1/albums/' + albumId)
      .withQueryParameters(actualOptions)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (actualCallback) {
      promise.then(function(data) {
        actualCallback(null, data);
      }, function(err) {
        actualCallback(err);
      });
    } else {
      return promise;
    }
  };

getAlbums

method
this.getAlbums()
  • @param: {string[]}albumIdsThe IDs of the albums.
  • @param: {Object}[options]The possible options, currently only market.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getAlbums(['0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing information about the albums. Not returned if a callback is given.

Description

Look up several albums.

Source

this.getAlbums = function(albumIds, options, callback) {
    // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function') {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = {};
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    var request = WebApiRequest.builder()
      .withPath('/v1/albums')
      .withQueryParameters({
        'ids' : albumIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, actualOptions);

    var promise = _performRequest(HttpManager.get, request);

    if (actualCallback) {
      promise.then(function(data) {
        actualCallback(null, data);
      }, function(err) {
        actualCallback(err);
      });
    } else {
      return promise;
    }
  };

getArtist

method
this.getArtist()
  • @param: {string}artistIdThe artist's ID.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: api.getArtist('1u7kkVrr14iBvrpYnZILJR').then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing information about the artist. Not returned if a callback is given.

Description

Look up an artist.

Source

this.getArtist = function(artistId, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/artists/' + artistId)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getArtists

method
this.getArtists()
  • @param: {string[]}artistIdsThe IDs of the artists.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getArtists(['0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing information about the artists. Not returned if a callback is given.

Description

Look up several artists.

Source

this.getArtists = function(artistIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/artists')
      .withQueryParameters({
        'ids' : artistIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

search

method
this.search()
  • @param: {string}queryThe search query.
  • @param: {string[]}typesAn array of item types to search across. Valid types are: 'album', 'artist', 'playlist', and 'track'.
  • @param: {Object}[options]The possible options, e.g. limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: search('Abba', ['track', 'playlist'], { limit : 5, offset : 1 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the search results. The result is paginated. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Search for music entities of certain types.

Source

this.search = function(query, types, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/search/')
      .withQueryParameters({
        type : types.join(','),
        q : query
      })
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

searchAlbums

method
this.searchAlbums()
  • @param: {string}queryThe search query.
  • @param: {Object}[options]The possible options, e.g. limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: searchAlbums('Space Oddity', { limit : 5, offset : 1 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the search results. The result is paginated. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Search for an album.

Source

this.searchAlbums = function(query, options, callback) {
    return this.search(query, ['album'], options, callback);
  };

searchArtists

method
this.searchArtists()
  • @param: {string}queryThe search query.
  • @param: {Object}[options]The possible options, e.g. limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: searchArtists('David Bowie', { limit : 5, offset : 1 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the search results. The result is paginated. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Search for an artist.

Source

this.searchArtists = function(query, options, callback) {
    return this.search(query, ['artist'], options, callback);
  };

searchTracks

method
this.searchTracks()
  • @param: {string}queryThe search query.
  • @param: {Object}[options]The possible options, e.g. limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: searchTracks('Mr. Brightside', { limit : 3, offset : 2 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the search results. The result is paginated. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Search for a track.

Source

this.searchTracks = function(query, options, callback) {
    return this.search(query, ['track'], options, callback);
  };

searchPlaylists

method
this.searchPlaylists()
  • @param: {string}queryThe search query.
  • @param: {Object}optionsThe possible options.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: searchPlaylists('workout', { limit : 1, offset : 0 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the search results. The result is paginated. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Search for playlists.

Source

this.searchPlaylists = function(query, options, callback) {
    return this.search(query, ['playlist'], options, callback);
  };

getArtistAlbums

method
this.getArtistAlbums()
  • @param: {string}artistIdThe artist's ID.
  • @options: {Object} [options] The possible options, e.g. limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getArtistAlbums('0oSGxfWSnnOXhD2fKuz2Gy', { album_type : 'album', country : 'GB', limit : 2, offset : 5 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the albums for the given artist. The result is paginated. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get an artist's albums.

Source

this.getArtistAlbums = function(artistId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/artists/' + artistId + '/albums')
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getAlbumTracks

method
this.getAlbumTracks()
  • @param: {albumId}thealbum's ID.
  • @options: {Object} [options] The possible options, e.g. limit.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getAlbumTracks('41MnTivkwTO3UUJ8DrqEJJ', { limit : 5, offset : 1 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the tracks in the album. The result is paginated. If the promise is rejected. it contains an error object. Not returned if a callback is given.

Description

Get the tracks of an album.

Source

this.getAlbumTracks = function(albumId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/albums/' + albumId + '/tracks')
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getArtistTopTracks

method
this.getArtistTopTracks()
  • @param: {string}artistIdThe artist's ID.
  • @param: {string}countryThe country/territory where the tracks are most popular. (format: ISO 3166-1 alpha-2)
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getArtistTopTracks('0oSGxfWSnnOXhD2fKuz2Gy', 'GB').then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the artist's top tracks in the given country. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get an artist's top tracks.

Source

this.getArtistTopTracks = function(artistId, country, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/artists/' + artistId + '/top-tracks')
      .withQueryParameters({
        'country' : country
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getArtistRelatedArtists

method
this.getArtistRelatedArtists()
  • @param: {string}artistIdThe artist's ID.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getArtistRelatedArtists('0oSGxfWSnnOXhD2fKuz2Gy').then(...)
  • @returns: {Promise|undefined} A promise that if successful, returns an object containing the related artists. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get related artists.

Source

this.getArtistRelatedArtists = function(artistId, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/artists/' + artistId + '/related-artists')
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getUser

method
this.getUser()
  • @param: {userId}Theuser ID.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getUser('thelinmichael').then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing information about the user. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get information about a user.

Source

this.getUser = function(userId, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId))
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getMe

method
this.getMe()
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getMe().then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing information about the user. The amount of information depends on the permissions given by the user. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get information about the user that has signed in (the current user).

Source

this.getMe = function(callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me')
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getUserPlaylists

method
this.getUserPlaylists()
  • @param: {string}userIdThe user ID.
  • @param: {Object}[options]The options supplied to this request.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getUserPlaylists('thelinmichael').then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a list of playlists. If rejected, it contains an error object. Not returned if a callback is given.

Description

Get a user's playlists.

Source

this.getUserPlaylists = function(userId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists')
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getPlaylist

method
this.getPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID.
  • @param: {string}playlistIdThe playlist's ID.
  • @param: {Object}[options]The options supplied to this request.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getPlaylist('thelinmichael', '3EsfV6XzCHU8SPNdbnFogK').then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing the playlist. If rejected, it contains an error object. Not returned if a callback is given.

Description

Get a playlist.

Source

this.getPlaylist = function(userId, playlistId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId)
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getPlaylistTracks

method
this.getPlaylistTracks()
  • @param: {string}userIdTHe playlist's owner's user ID.
  • @param: {string}playlistIdThe playlist's ID.
  • @param: {Object}[options]Optional options, such as fields.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getPlaylistTracks('thelinmichael', '3ktAYNcRHpazJ9qecm3ptn').then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object that containing the tracks in the playlist. If rejected, it contains an error object. Not returned if a callback is given.

Description

Get tracks in a playlist.

Source

this.getPlaylistTracks = function(userId, playlistId, options, callback) {
    var request = WebApiRequest.builder().
      withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/tracks').
      withQueryParameters(options).
      build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

createPlaylist

method
this.createPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID.
  • @param: {string}playlistNameThe name of the playlist.
  • @param: {Object}[options]The possible options, currently only public.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: createPlaylist('thelinmichael', 'My cool playlist!', { public : false }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing information about the created playlist. If rejected, it contains an error object. Not returned if a callback is given.

Description

Create a playlist.

Source

this.createPlaylist = function(userId, playlistName, options, callback) {
    // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function') {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = { 'name' : playlistName };
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withBodyParameters(actualOptions)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.post, request);

    if (actualCallback) {
      promise.then(function(data) {
        actualCallback(null, data);
      }, function(err) {
        actualCallback(err);
      });
    } else {
      return promise;
    }
  };

followPlaylist

method
this.followPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {Object}[options]The possible options, currently only public.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Follow a playlist.

Source

this.followPlaylist = function(userId, playlistId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/followers')
      .withBodyParameters(options)
      .withHeaders({ 'Content-Type' : 'application/json' })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

unfollowPlaylist

method
this.unfollowPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {Object}[options]The possible options, currently only public.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Unfollow a playlist.

Source

this.unfollowPlaylist = function(userId, playlistId, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/followers')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

changePlaylistDetails

method
this.changePlaylistDetails()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {Object}[options]The possible options, e.g. name, public.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: changePlaylistDetails('thelinmichael', '3EsfV6XzCHU8SPNdbnFogK', {name: 'New name', public: true}).then(...)
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Change playlist details.

Source

this.changePlaylistDetails = function(userId, playlistId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId)
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withBodyParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

addTracksToPlaylist

method
this.addTracksToPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {string[]}tracksURIs of the tracks to add to the playlist.
  • @param: {Object}[options]Options, position being the only one.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: addTracksToPlaylist('thelinmichael', '3EsfV6XzCHU8SPNdbnFogK', '["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"]').then(...)
  • @returns: {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, it contains an error object. Not returned if a callback is given.

Description

Add tracks to a playlist.

Source

this.addTracksToPlaylist = function(userId, playlistId, tracks, options, callback) {
    var tracksString;
    if (typeof tracks === 'object') {
      tracksString = tracks.join();
    } else {
      tracksString = tracks;
    }
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/tracks')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withQueryParameters({
        uris: tracksString
      })
      .build();

    _addQueryParameters(request, options);
    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.post, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

removeTracksFromPlaylist

method
this.removeTracksFromPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {Object[]}tracksAn array of objects containing a property called uri with the track URI (String), and a an optional property called positions (int[]), e.g. { uri : "spotify:track:491rM2JN8KvmV6p0oDDuJT", positions : [0, 15] }
  • @param: {Object}optionsOptions, snapshot_id being the only one.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, it contains an error object. Not returned if a callback is given.

Description

Remove tracks from a playlist.

Source

this.removeTracksFromPlaylist = function(userId, playlistId, tracks, options, callback) {
    var request = WebApiRequest.builder().
      withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/tracks').
      withHeaders({ 'Content-Type' : 'application/json' }).
      withBodyParameters({
        'tracks': tracks
      }).
      build();

    _addBodyParameters(request, options);
    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

removeTracksFromPlaylistByPosition

method
this.removeTracksFromPlaylistByPosition()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {int[]}positionsThe positions of the tracks in the playlist that should be removed
  • @param: {string}snapshot_idThe snapshot ID, or version, of the playlist. Required
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, it contains an error object. Not returned if a callback is given.

Description

Remove tracks from a playlist by position instead of specifying the tracks' URIs.

Source

this.removeTracksFromPlaylistByPosition = function(userId, playlistId, positions, snapshotId, callback) {
    var request = WebApiRequest.builder().
      withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/tracks').
      withHeaders({ 'Content-Type' : 'application/json' }).
      withBodyParameters({
        'positions': positions,
        'snapshot_id' : snapshotId
      }).
      build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

replaceTracksInPlaylist

method
this.replaceTracksInPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {Object[]}urisAn array of track URIs (strings)
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Replace tracks in a playlist.

Source

this.replaceTracksInPlaylist = function(userId, playlistId, uris, callback) {
    var request = WebApiRequest.builder().
      withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/tracks').
      withHeaders({ 'Content-Type' : 'application/json' }).
      withBodyParameters({
        'uris': uris
      }).
      build();

    _addAccessToken(request, this.getAccessToken());

    var promise =  _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

reorderTracksInPlaylist

method
this.reorderTracksInPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {int}rangeStartThe position of the first track to be reordered.
  • @param: {int}insertBeforeThe position where the tracks should be inserted.
  • @param: {Object}optionsOptional parameters, i.e. range_length and snapshot_id.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns an object containing a snapshot_id. If rejected, it contains an error object. Not returned if a callback is given.

Description

Reorder tracks in a playlist.

Source

this.reorderTracksInPlaylist = function(userId, playlistId, rangeStart, insertBefore, options, callback) {
    var request = WebApiRequest.builder().
      withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/tracks').
      withHeaders({ 'Content-Type' : 'application/json' }).
      withBodyParameters({
        'range_start': rangeStart,
        'insert_before' : insertBefore
      }).
      build();

    _addAccessToken(request, this.getAccessToken());
    _addBodyParameters(request, options);

    var promise =  _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getAudioFeaturesForTrack

method
this.getAudioFeaturesForTrack()
  • @param: {string}trackIdThe track ID
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getAudioFeaturesForTrack('38P3Q4QcdjQALGF2Z92BmR').then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing information about the audio features. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get audio features for a single track identified by its unique Spotify ID.

Source

this.getAudioFeaturesForTrack = function(trackId, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/audio-features/' + trackId)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getAudioFeaturesForTracks

method
this.getAudioFeaturesForTracks()
  • @param: {string[]}trackIdsThe track IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getAudioFeaturesForTracks(['38P3Q4QcdjQALGF2Z92BmR', '2HO2bnoMrpnZUbUqiilLHi']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing information about the audio features for the tracks. If the promise is rejected, it contains an error object. Not returned if a callback is given.

Description

Get audio features for multiple tracks identified by their unique Spotify ID.

Source

this.getAudioFeaturesForTracks = function(trackIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/audio-features')
      .withQueryParameters({
        'ids' : trackIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getRecommendations

method
this.getRecommendations()
  • @param: {Object}[options]The options supplied to this request.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getRecommendations({ min_energy: 0.4, seed_artists: ['6mfK6Q2tzLMEchAr0e9Uzu', '4DYFVNKZ1uixa6SQTvzQwJ'], min_popularity: 50 }).then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a list of tracks and a list of seeds. If rejected, it contains an error object. Not returned if a callback is given.

Description

Create a playlist-style listening experience based on seed artists, tracks and genres.

Source

this.getRecommendations = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/recommendations')
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getAvailableGenreSeeds

method
this.getAvailableGenreSeeds()
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: getAvailableGenreSeeds().then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a list of available genres to be used as seeds for recommendations. If rejected, it contains an error object. Not returned if a callback is given.

Description

Retrieve a list of available genres seed parameter values for recommendations.

Source

this.getAvailableGenreSeeds = function(callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/recommendations/available-genre-seeds')
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

clientCredentialsGrant

method
this.clientCredentialsGrant()
  • @param: {Object}optionsOptions.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves into an object containing the access token, token type and time to expiration. If rejected, it contains an error object. Not returned if a callback is given.

Description

Request an access token using the Client Credentials flow.
Requires that client ID and client secret has been set previous to the call.

Source

this.clientCredentialsGrant = function(options, callback) {
    var request = AuthenticationRequest.builder()
      .withPath('/api/token')
      .withBodyParameters({
        'grant_type' : 'client_credentials'
      })
      .withHeaders({
        Authorization : ('Basic ' + new Buffer(this.getClientId() + ':' + this.getClientSecret()).toString('base64'))
      })
      .build();

    _addBodyParameters(request, options);

    var promise =  _performRequest(HttpManager.post, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

authorizationCodeGrant

method
this.authorizationCodeGrant()
  • @param: {string}codeThe authorization code returned in the callback in the Authorization Code flow.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves into an object containing the access token, refresh token, token type and time to expiration. If rejected, it contains an error object. Not returned if a callback is given.

Description

Request an access token using the Authorization Code flow.
Requires that client ID, client secret, and redirect URI has been set previous to the call.

Source

this.authorizationCodeGrant = function(code, callback) {
    var request = AuthenticationRequest.builder()
      .withPath('/api/token')
      .withBodyParameters({
        'grant_type' : 'authorization_code',
        'redirect_uri' : this.getRedirectURI(),
        'code' : code,
        'client_id' : this.getClientId(),
        'client_secret' : this.getClientSecret()
      })
      .build();

    var promise = _performRequest(HttpManager.post, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

refreshAccessToken

method
this.refreshAccessToken()
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing the access token, time to expiration and token type. If rejected, it contains an error object. Not returned if a callback is given.

Description

Refresh the access token given that it hasn't expired.
Requires that client ID, client secret and refresh token has been set previous to the call.

Source

this.refreshAccessToken = function(callback) {
    var request = AuthenticationRequest.builder()
      .withPath('/api/token')
      .withBodyParameters({
        'grant_type' : 'refresh_token',
        'refresh_token' : this.getRefreshToken()
      })
      .withHeaders({
        Authorization : ('Basic ' + new Buffer(this.getClientId() + ':' + this.getClientSecret()).toString('base64'))
      })
      .build();

    var promise = _performRequest(HttpManager.post, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

createAuthorizeURL

method
this.createAuthorizeURL()
  • @param: {string[]}scopesThe scopes corresponding to the permissions the application needs.
  • @param: {string}stateA parameter that you can use to maintain a value between the request and the callback to redirect_uri.It is useful to prevent CSRF exploits.
  • @returns: {string} The URL where the user can give application permissions.

Description

Retrieve a URL where the user can give the application permissions.

Source

this.createAuthorizeURL = function(scopes, state) {
    var request = AuthenticationRequest.builder()
      .withPath('/authorize')
      .withQueryParameters({
        'client_id' : this.getClientId(),
        'response_type' : 'code',
        'redirect_uri' : this.getRedirectURI(),
        'scope' : scopes.join('%20'),
        'state' : state
      })
      .build();

    return request.getURL();
  };

getMySavedTracks

method
this.getMySavedTracks()
  • @param: {Object}[options]Options, being market, limit, and/or offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which in turn contains playlist track objects. Not returned if a callback is given.

Description

Retrieve the tracks that are saved to the authenticated users Your Music library.

Source

this.getMySavedTracks = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/tracks')
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

containsMySavedTracks

method
this.containsMySavedTracks()
  • @param: {string[]}trackIdsThe track IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves into an array of booleans. The order of the returned array's elements correspond to the track ID in the request. The boolean value of true indicates that the track is part of the user's library, otherwise false. Not returned if a callback is given.

Description

Check if one or more tracks is already saved in the current Spotify user’s “Your Music” library.

Source

this.containsMySavedTracks = function(trackIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/tracks/contains')
      .withQueryParameters({
        'ids' : trackIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

removeFromMySavedTracks

method
this.removeFromMySavedTracks()
  • @param: {string[]}trackIdsThe track IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given.

Description

Remove a track from the authenticated user's Your Music library.

Source

this.removeFromMySavedTracks = function(trackIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/tracks')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withBodyParameters(trackIds)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

addToMySavedTracks

method
this.addToMySavedTracks()
  • @param: {string[]}trackIdsThe track IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given.

Description

Add a track from the authenticated user's Your Music library.

Source

this.addToMySavedTracks = function(trackIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/tracks')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withBodyParameters(trackIds)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

removeFromMySavedAlbums

method
this.removeFromMySavedAlbums()
  • @param: {string[]}albumIdsThe album IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given.

Description

Remove an album from the authenticated user's Your Music library.

Source

this.removeFromMySavedAlbums = function(albumIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/albums')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withBodyParameters(albumIds)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

addToMySavedAlbums

method
this.addToMySavedAlbums()
  • @param: {string[]}albumIdsThe track IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns null, otherwise an error. Not returned if a callback is given.

Description

Add an album from the authenticated user's Your Music library.

Source

this.addToMySavedAlbums = function(albumIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/albums')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withBodyParameters(albumIds)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getMySavedAlbums

method
this.getMySavedAlbums()
  • @param: {Object}[options]Options, being market, limit, and/or offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which in turn contains playlist album objects. Not returned if a callback is given.

Description

Retrieve the albums that are saved to the authenticated users Your Music library.

Source

this.getMySavedAlbums = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/albums')
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

containsMySavedAlbums

method
this.containsMySavedAlbums()
  • @param: {string[]}albumIdsThe album IDs
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves into an array of booleans. The order of the returned array's elements correspond to the album ID in the request. The boolean value of true indicates that the album is part of the user's library, otherwise false. Not returned if a callback is given.

Description

Check if one or more albums is already saved in the current Spotify user’s “Your Music” library.

Source

this.containsMySavedAlbums = function(albumIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/albums/contains')
      .withQueryParameters({
        'ids' : albumIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getMyTopArtists

method
this.getMyTopArtists()
  • @param: {Object}[options]Options, being time_range, limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves into a paging object of artists, otherwise an error. Not returned if a callback is given.

Description

Get the current user's top artists based on calculated affinity.

Source

this.getMyTopArtists = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/top/artists')
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getMyTopTracks

method
this.getMyTopTracks()
  • @param: {Object}[options]Options, being time_range, limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves into a paging object of tracks, otherwise an error. Not returned if a callback is given.

Description

Get the current user's top tracks based on calculated affinity.

Source

this.getMyTopTracks = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/top/tracks')
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

followUsers

method
this.followUsers()
  • @param: {string[]}userIdsThe IDs of the users to be followed.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: followUsers(['thelinmichael', 'wizzler']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Add the current user as a follower of one or more other Spotify users.

Source

this.followUsers = function(userIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following')
      .withQueryParameters({
        ids: userIds.join(','),
        type: 'user'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

followArtists

method
this.followArtists()
  • @param: {string[]}artistIdsThe IDs of the artists to be followed.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: followArtists(['0LcJLqbBmaGUft1e9Mm8HV', '3gqv1kgivAc92KnUm4elKv']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Add the current user as a follower of one or more artists.

Source

this.followArtists = function(artistIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following')
      .withQueryParameters({
        ids: artistIds.join(','),
        type: 'artist'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.put, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

unfollowUsers

method
this.unfollowUsers()
  • @param: {string[]}userIdsThe IDs of the users to be unfollowed.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: unfollowUsers(['thelinmichael', 'wizzler']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Remove the current user as a follower of one or more other Spotify users.

Source

this.unfollowUsers = function(userIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following')
      .withQueryParameters({
        ids: userIds.join(','),
        type: 'user'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

unfollowArtists

method
this.unfollowArtists()
  • @param: {string[]}artistIdsThe IDs of the artists to be unfollowed.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: unfollowArtists(['0LcJLqbBmaGUft1e9Mm8HV', '3gqv1kgivAc92KnUm4elKv']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, simply resolves to an empty object. If rejected, it contains an error object. Not returned if a callback is given.

Description

Remove the current user as a follower of one or more artists.

Source

this.unfollowArtists = function(artistIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following')
      .withQueryParameters({
        ids: artistIds.join(','),
        type: 'artist'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.del, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

isFollowingUsers

method
this.isFollowingUsers()
  • @param: {string[]}userIdsThe IDs of the users to check if are followed by the current user.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: isFollowingUsers(['thelinmichael', 'wizzler']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves into an array of booleans. The order of the returned array's elements correspond to the users IDs in the request. The boolean value of true indicates that the user is following that user, otherwise is not. Not returned if a callback is given.

Description

Check to see if the current user is following one or more other Spotify users.

Source

this.isFollowingUsers = function(userIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following/contains')
      .withQueryParameters({
        ids: userIds.join(','),
        type: 'user'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getFollowedArtists

method
this.getFollowedArtists()
  • @param: {Object}[options]Options, being after and limit.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains album objects. Not returned if a callback is given.

Description

Get the current user's followed artists.

Source

this.getFollowedArtists = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withQueryParameters({
        type : 'artist'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());
    _addQueryParameters(request, options);

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

areFollowingPlaylist

method
this.areFollowingPlaylist()
  • @param: {string}userIdThe playlist's owner's user ID
  • @param: {string}playlistIdThe playlist's ID
  • @param: {String[]}UserIDs of the following users
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful returns an array of booleans. If rejected, it contains an error object. Not returned if a callback is given.

Description

Check if users are following a playlist.

Source

this.areFollowingPlaylist = function(userId, playlistId, followerIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/users/' + encodeURI(userId) + '/playlists/' + playlistId + '/followers/contains')
      .withQueryParameters({
        ids : followerIds.join(',')
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

isFollowingArtists

method
this.isFollowingArtists()
  • @param: {string[]}artistIdsThe IDs of the artists to check if are followed by the current user.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @example: isFollowingArtists(['0LcJLqbBmaGUft1e9Mm8HV', '3gqv1kgivAc92KnUm4elKv']).then(...)
  • @returns: {Promise|undefined} A promise that if successful, resolves into an array of booleans. The order of the returned array's elements correspond to the artists IDs in the request. The boolean value of true indicates that the user is following that artist, otherwise is not. Not returned if a callback is given.

Description

Check to see if the current user is following one or more artists.

Source

this.isFollowingArtists = function(artistIds, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/me/following/contains')
      .withQueryParameters({
        ids: artistIds.join(','),
        type: 'artist'
      })
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getNewReleases

method
this.getNewReleases()
  • @param: {Object}[options]Options, being country, limit and/or offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains album objects. Not returned if a callback is given.

Description

Retrieve new releases

Source

this.getNewReleases = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/browse/new-releases')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getFeaturedPlaylists

method
this.getFeaturedPlaylists()
  • @param: {Object}[options]Options, being country, locale, timestamp, limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a paging object which contains featured playlists. Not returned if a callback is given.

Description

Retrieve featured playlists

Source

this.getFeaturedPlaylists = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/browse/featured-playlists')
      .withHeaders({ 'Content-Type' : 'application/json' })
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise =  _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getCategories

method
this.getCategories()
  • @param: {Object}[options]Options, being country, locale, limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a paging object of categories. Not returned if a callback is given.

Description

Retrieve a list of categories used to tag items in Spotify (e.g. in the 'Browse' tab)

Source

this.getCategories = function(options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/browse/categories')
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getCategory

method
this.getCategory()
  • @param: {string}categoryIdThe id of the category to retrieve.
  • @param: {Object}[options]Options, being country, locale.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to an object containing a category object. Not returned if a callback is given.

Description

Retrieve a category.

Source

this.getCategory = function(categoryId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/browse/categories/' + categoryId)
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

getPlaylistsForCategory

method
this.getPlaylistsForCategory()
  • @param: {string}categoryIdThe id of the category to retrieve playlists for.
  • @param: {Object}[options]Options, being country, limit, offset.
  • @param: {requestCallback}[callback]Optional callback method to be called instead of the promise.
  • @returns: {Promise|undefined} A promise that if successful, resolves to a paging object containing simple playlists. Not returned if a callback is given.

Description

Retrieve playlists for a category.

Source

this.getPlaylistsForCategory = function(categoryId, options, callback) {
    var request = WebApiRequest.builder()
      .withPath('/v1/browse/categories/' + categoryId + '/playlists')
      .withQueryParameters(options)
      .build();

    _addAccessToken(request, this.getAccessToken());

    var promise = _performRequest(HttpManager.get, request);

    if (callback) {
      promise.then(function(data) {
        callback(null, data);
      }, function(err) {
        callback(err);
      });
    } else {
      return promise;
    }
  };

}

module.exports = SpotifyWebApi;