spotify-web-api-node (master) doxdox documentation

A Node.js wrapper for Spotify's Web API

# documented()

This example refreshes an access token. Refreshing access tokens is only possible access tokens received using the Authorization Code flow, documented here: https://developer.spotify.com/spotify-web-api/authorization-guide/#authorization_code_flow

# spotifyApi()

Set the credentials given on Spotify's My Applications page. https://developer.spotify.com/my-applications

# spotifyApi()

Set the credentials given on Spotify's My Applications page. https://developer.spotify.com/my-applications

# spotifyApi()

Set the credentials given on Spotify's My Applications page. https://developer.spotify.com/my-applications

# spotifyApi()

Set the credentials given on Spotify's My Applications page. https://developer.spotify.com/my-applications

# documented()

This example retrieves information about the 'current' user. The current user is the user that has authorized the application to access its data.

# spotifyApi()

This endpoint doesn't require an access token, but it's beneficial to use one as it gives the application a higher rate limit. Since it's not necessary to get an access token connected to a specific user, this example uses the Client Credentials flow. This flow uses only the client ID and the client secret. https://developer.spotify.com/spotify-web-api/authorization-guide/#client_credentials_flow

# HttpManager.del(The, The)

Make a HTTP DELETE request.

Parameters

Name Types Description
The BaseRequest request.
The Function callback function.

# HttpManager.get(The, The)

Make a HTTP GET request.

Parameters

Name Types Description
The BaseRequest request.
The Function callback function.

# HttpManager.post(The, The)

Make a HTTP POST request.

Parameters

Name Types Description
The BaseRequest request.
The Function callback function.

# HttpManager.put(The, The)

Make a HTTP PUT request.

Parameters

Name Types Description
The BaseRequest request.
The Function callback function.

# authorizationCodeGrant(code, callback)

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.

Parameters

Name Types Description
code string The authorization code returned in the callback in the Authorization Code flow.
callback requestCallback Optional callback method to be called instead of the promise.

# clientCredentialsGrant(options, callback)

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

Parameters

Name Types Description
options Object Options.
callback requestCallback Optional callback method to be called instead of the promise.

# refreshAccessToken(callback)

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.

Parameters

Name Types Description
callback requestCallback Optional callback method to be called instead of the promise.

# addToMySavedAlbums(albumIds, callback)

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

Parameters

Name Types Description
albumIds string[] The track IDs
callback requestCallback Optional callback method to be called instead of the promise.

# addToMySavedTracks(trackIds, callback)

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

Parameters

Name Types Description
trackIds string[] The track IDs
callback requestCallback Optional callback method to be called instead of the promise.

# addTracksToPlaylist(userId, playlistId, tracks, options, callback)

Add tracks to a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
tracks string[] URIs of the tracks to add to the playlist.
options Object Options, position being the only one.
callback requestCallback Optional callback method to be called instead of the promise.

# areFollowingPlaylist(userId, playlistId, User, callback)

Check if users are following a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
User String[] IDs of the following users
callback requestCallback Optional callback method to be called instead of the promise.

# changePlaylistDetails(userId, playlistId, options, callback)

Change playlist details.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
options Object The possible options, e.g. name, public.
callback requestCallback Optional callback method to be called instead of the promise.

# containsMySavedAlbums(albumIds, callback)

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

Parameters

Name Types Description
albumIds string[] The album IDs
callback requestCallback Optional callback method to be called instead of the promise.

# containsMySavedTracks(trackIds, callback)

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

Parameters

Name Types Description
trackIds string[] The track IDs
callback requestCallback Optional callback method to be called instead of the promise.

# createAuthorizeURL(scopes, state, showDialog)

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

Parameters

Name Types Description
scopes string[] The scopes corresponding to the permissions the application needs.
state string A 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.
showDialog boolean A parameter that you can use to force the user to approve the app on each login rather than being automatically redirected.

# createPlaylist(userId, playlistName, options, callback)

Create a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID.
playlistName string The name of the playlist.
options Object The possible options, currently only public.
callback requestCallback Optional callback method to be called instead of the promise.

# e64URI(userId, playlistId, base64URI, callback)

Replace the image used to represent a specific playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
base64URI string Base64 encoded JPEG image data, maximum payload size is 256 KB
callback requestCallback Optional callback method to be called instead of the promise.

# es(options, callback)

Retrieve new releases

Parameters

Name Types Description
options Object Options, being country, limit and/or offset.
callback requestCallback Optional callback method to be called instead of the promise.

# followArtists(artistIds, callback)

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

Parameters

Name Types Description
artistIds string[] The IDs of the artists to be followed.
callback requestCallback Optional callback method to be called instead of the promise.

# followPlaylist(userId, playlistId, options, callback)

Follow a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
options Object The possible options, currently only public.
callback requestCallback Optional callback method to be called instead of the promise.

# followUsers(userIds, callback)

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

Parameters

Name Types Description
userIds string[] The IDs of the users to be followed.
callback requestCallback Optional callback method to be called instead of the promise.

# getAlbum(albumId, options, callback)

Look up an album.

Parameters

Name Types Description
albumId string The album's ID.
options Object The possible options, currently only market.
callback requestCallback Optional callback method to be called instead of the promise.

# getAlbums(albumIds, options, callback)

Look up several albums.

Parameters

Name Types Description
albumIds string[] The IDs of the albums.
options Object The possible options, currently only market.
callback requestCallback Optional callback method to be called instead of the promise.

# getAlbumTracks(albumId, callback)

Get the tracks of an album.

Parameters

Name Types Description
albumId the album's ID.
callback requestCallback Optional callback method to be called instead of the promise.

# getArtist(artistId, callback)

Look up an artist.

Parameters

Name Types Description
artistId string The artist's ID.
callback requestCallback Optional callback method to be called instead of the promise.

# getArtistAlbums(artistId, callback)

Get an artist's albums.

Parameters

Name Types Description
artistId string The artist's ID.
callback requestCallback Optional callback method to be called instead of the promise.

# getArtistRelatedArtists(artistId, callback)

Get related artists.

Parameters

Name Types Description
artistId string The artist's ID.
callback requestCallback Optional callback method to be called instead of the promise.

# getArtists(artistIds, callback)

Look up several artists.

Parameters

Name Types Description
artistIds string[] The IDs of the artists.
callback requestCallback Optional callback method to be called instead of the promise.

# getArtistTopTracks(artistId, country, callback)

Get an artist's top tracks.

Parameters

Name Types Description
artistId string The artist's ID.
country string The country/territory where the tracks are most popular. (format: ISO 3166-1 alpha-2)
callback requestCallback Optional callback method to be called instead of the promise.

# getAudioAnalysisForTrack(trackId, callback)

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

Parameters

Name Types Description
trackId string The track ID
callback requestCallback Optional callback method to be called instead of the promise.

# getAudioFeaturesForTrack(trackId, callback)

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

Parameters

Name Types Description
trackId string The track ID
callback requestCallback Optional callback method to be called instead of the promise.

# getAudioFeaturesForTracks(trackIds, callback)

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

Parameters

Name Types Description
trackIds string[] The track IDs
callback requestCallback Optional callback method to be called instead of the promise.

# getAvailableGenreSeeds(callback)

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

Parameters

Name Types Description
callback requestCallback Optional callback method to be called instead of the promise.

# getCategories(options, callback)

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

Parameters

Name Types Description
options Object Options, being country, locale, limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getCategory(categoryId, options, callback)

Retrieve a category.

Parameters

Name Types Description
categoryId string The id of the category to retrieve.
options Object Options, being country, locale.
callback requestCallback Optional callback method to be called instead of the promise.

# getFeaturedPlaylists(options, callback)

Retrieve featured playlists

Parameters

Name Types Description
options Object Options, being country, locale, timestamp, limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getFollowedArtists(options, callback)

Get the current user's followed artists.

Parameters

Name Types Description
options Object Options, being after and limit.
callback requestCallback Optional callback method to be called instead of the promise.

# getMe(callback)

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

Parameters

Name Types Description
callback requestCallback Optional callback method to be called instead of the promise.

# getMyCurrentPlaybackState(options, callback)

Get the Current User's Current Playback State

Parameters

Name Types Description
options Object Options, being market.
callback requestCallback Optional callback method to be called instead of the promise.

# getMyCurrentPlayingTrack(options, callback)

Get the Current User's Currently Playing Track.

Parameters

Name Types Description
options Object Options, being market.
callback requestCallback Optional callback method to be called instead of the promise.

# getMyDevices(callback)

Get the Current User's Connect Devices

Parameters

Name Types Description
callback requestCallback Optional callback method to be called instead of the promise.

# getMyRecentlyPlayedTracks(options, callback)

Get the Current User's Recently Played Tracks

Parameters

Name Types Description
options Object Options, being type, after, limit, before.
callback requestCallback Optional callback method to be called instead of the promise.

# getMySavedAlbums(options, callback)

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

Parameters

Name Types Description
options Object Options, being market, limit, and/or offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getMySavedTracks(options, callback)

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

Parameters

Name Types Description
options Object Options, being market, limit, and/or offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getMyTopArtists(options, callback)

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

Parameters

Name Types Description
options Object Options, being time_range, limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getMyTopTracks(options, callback)

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

Parameters

Name Types Description
options Object Options, being time_range, limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getPlaylist(userId, playlistId, options, callback)

Get a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID.
playlistId string The playlist's ID.
options Object The options supplied to this request.
callback requestCallback Optional callback method to be called instead of the promise.

# getPlaylistsForCategory(categoryId, options, callback)

Retrieve playlists for a category.

Parameters

Name Types Description
categoryId string The id of the category to retrieve playlists for.
options Object Options, being country, limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# getPlaylistTracks(userId, playlistId, options, callback)

Get tracks in a playlist.

Parameters

Name Types Description
userId string THe playlist's owner's user ID.
playlistId string The playlist's ID.
options Object Optional options, such as fields.
callback requestCallback Optional callback method to be called instead of the promise.

# getRecommendations(options, callback)

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

Parameters

Name Types Description
options Object The options supplied to this request.
callback requestCallback Optional callback method to be called instead of the promise.

# getTrack(trackId, options, callback)

Look up a track.

Parameters

Name Types Description
trackId string The track's ID.
options Object The possible options, currently only market.
callback requestCallback Optional callback method to be called instead of the promise.

# getTracks(trackIds, options, callback)

Look up several tracks.

Parameters

Name Types Description
trackIds string[] The IDs of the artists.
options Object The possible options, currently only market.
callback requestCallback Optional callback method to be called instead of the promise.

# getUser(userId, callback)

Get information about a user.

Parameters

Name Types Description
userId The user ID.
callback requestCallback Optional callback method to be called instead of the promise.

# getUserPlaylists(userId, options, callback)

Get a user's playlists.

Parameters

Name Types Description
userId string An optional id of the user. If you know the Spotify URI it is easy to find the id (e.g. spotify:user:<here_is_the_id>). If not provided, the id of the user that granted the permissions will be used.
options Object The options supplied to this request.
callback requestCallback Optional callback method to be called instead of the promise.

# isFollowingArtists(artistIds, callback)

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

Parameters

Name Types Description
artistIds string[] The IDs of the artists to check if are followed by the current user.
callback requestCallback Optional callback method to be called instead of the promise.

# isFollowingUsers(userIds, callback)

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

Parameters

Name Types Description
userIds string[] The IDs of the users to check if are followed by the current user.
callback requestCallback Optional callback method to be called instead of the promise.

# pause(options, callback)

Pauses the Current User's Playback

Parameters

Name Types Description
options Object Options, for now device_id,
callback requestCallback Optional callback method to be called instead of the promise.

# play(options, callback)

Starts o Resumes the Current User's Playback

Parameters

Name Types Description
options Object Options, being device_id, context_uri, offset, uris.
callback requestCallback Optional callback method to be called instead of the promise.

# removeFromMySavedAlbums(albumIds, callback)

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

Parameters

Name Types Description
albumIds string[] The album IDs
callback requestCallback Optional callback method to be called instead of the promise.

# removeFromMySavedTracks(trackIds, callback)

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

Parameters

Name Types Description
trackIds string[] The track IDs
callback requestCallback Optional callback method to be called instead of the promise.

# removeTracksFromPlaylist(userId, playlistId, tracks, options, callback)

Remove tracks from a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
tracks Object[] An 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] }
options Object Options, snapshot_id being the only one.
callback requestCallback Optional callback method to be called instead of the promise.

# removeTracksFromPlaylistByPosition(userId, playlistId, positions, snapshot_id, callback)

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

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
positions int[] The positions of the tracks in the playlist that should be removed
snapshot_id string The snapshot ID, or version, of the playlist. Required
callback requestCallback Optional callback method to be called instead of the promise.

# reorderTracksInPlaylist(userId, playlistId, rangeStart, insertBefore, options, callback)

Reorder tracks in a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
rangeStart int The position of the first track to be reordered.
insertBefore int The position where the tracks should be inserted.
options Object Optional parameters, i.e. range_length and snapshot_id.
callback requestCallback Optional callback method to be called instead of the promise.

# replaceTracksInPlaylist(userId, playlistId, uris, callback)

Replace tracks in a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
uris Object[] An array of track URIs (strings)
callback requestCallback Optional callback method to be called instead of the promise.

# search(query, types, options, callback)

Search for music entities of certain types.

Parameters

Name Types Description
query string The search query.
types string[] An array of item types to search across. Valid types are: 'album', 'artist', 'playlist', and 'track'.
options Object The possible options, e.g. limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# searchAlbums(query, options, callback)

Search for an album.

Parameters

Name Types Description
query string The search query.
options Object The possible options, e.g. limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# searchArtists(query, options, callback)

Search for an artist.

Parameters

Name Types Description
query string The search query.
options Object The possible options, e.g. limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# searchPlaylists(query, options, callback)

Search for playlists.

Parameters

Name Types Description
query string The search query.
options Object The possible options.
callback requestCallback Optional callback method to be called instead of the promise.

# searchTracks(query, options, callback)

Search for a track.

Parameters

Name Types Description
query string The search query.
options Object The possible options, e.g. limit, offset.
callback requestCallback Optional callback method to be called instead of the promise.

# setRepeat(options, callback)

Set Repeat Mode On The Current User's Playback

Parameters

Name Types Description
options Object Options, being state (track, context, off).
callback requestCallback Optional callback method to be called instead of the promise.

# setShuffle(options, callback)

Set Shuffle Mode On The Current User's Playback

Parameters

Name Types Description
options Object Options, being state (true, false).
callback requestCallback Optional callback method to be called instead of the promise.

# skipToNext(callback)

Skip the Current User's Playback To Next Track

Parameters

Name Types Description
callback requestCallback Optional callback method to be called instead of the promise.

# skipToPrevious(callback)

Skip the Current User's Playback To Previous Track

Parameters

Name Types Description
callback requestCallback Optional callback method to be called instead of the promise.

# transferMyPlayback(options, callback)

Transfer a User's Playback

Parameters

Name Types Description
options Object Options, being market.
callback requestCallback Optional callback method to be called instead of the promise.

# unfollowArtists(artistIds, callback)

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

Parameters

Name Types Description
artistIds string[] The IDs of the artists to be unfollowed.
callback requestCallback Optional callback method to be called instead of the promise.

# unfollowPlaylist(userId, playlistId, options, callback)

Unfollow a playlist.

Parameters

Name Types Description
userId string The playlist's owner's user ID
playlistId string The playlist's ID
options Object The possible options, currently only public.
callback requestCallback Optional callback method to be called instead of the promise.

# unfollowUsers(userIds, callback)

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

Parameters

Name Types Description
userIds string[] The IDs of the users to be unfollowed.
callback requestCallback Optional callback method to be called instead of the promise.