Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spotify-web-client

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spotify-web-client

A fully typed client for node and browser environments.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

spotify-web-client

A fully typed client for node and browser environments.

🚀 Quick Start

Install:

# npm
npm i spotify-web-client

# yarn
yarn add spotify-web-client

Import:

// ESM / Typescript
import { SpotifyClient } from 'spotify-web-client'

// CommonJS
const { SpotifyClient } = require('spotify-web-client')

Usage

const token = '...' // Generate an access token with OAuth

const client = new SpotifyClient().setAccessToken(token)

// Get currently played song
const playbackState = await client.player.getPlaybackState()
if (playbackState.item?.type === 'track') {
  // playbackState.item narrowed to TrackObject
  console.log(playbackState.item.name)
}

📦 Available APIs

🔒 Authentication

These methods can be accessed directly through your SpotifyClient instance.

MethodDescription
setAccessTokenSets the access_token for the current instance of SpotifyClient
setRefreshTokenSets the refresh_token for the current instance of SpotifyClient
generateOAuthUrlGenerates an OAuth link with the provided scope
getAccessTokenExchanges an authorization code for an access_token and a refresh_token
refreshTokenObtain a new access_token from a refresh token

💿 Albums

These methods can be accessed through the albums key of your SpotifyClient instance.

MethodDescription
getAlbumGet Spotify catalog information for a single album.
getAlbumsGet Spotify catalog information for multiple albums identified by their Spotify IDs.
getAlbumTracksGet Spotify catalog information about an album’s tracks. Optional parameters can be used to limit the number of tracks returned.
getSavedAlbumsGet a list of the albums saved in the current Spotify user's 'Your Music' library.
saveAlbumsSave one or more albums to the current user's 'Your Music' library.
removeAlbumsRemove one or more albums from the current user's 'Your Music' library.
checkUserSavedAlbumsCheck if one or more albums is already saved in the current Spotify user's 'Your Music' library.
getReleasesGet a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).

🎤 Artists

These methods can be accessed through the artists key of your SpotifyClient instance.

MethodDescription
getArtistGet Spotify catalog information for a single artist identified by their unique Spotify ID.
getArtistsGet Spotify catalog information for several artists based on their Spotify IDs.
getArtistAlbumsGet Spotify catalog information about an artist's albums.
getArtistTopTracksGet Spotify catalog information about an artist's top tracks by country.
getRelatedArtistsGet Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the Spotify community's listening history.

📗 Audiobooks

These methods can be accessed through the audiobooks key of your SpotifyClient instance.

Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.

MethodDescription
getAudiobookGet Spotify catalog information for a single audiobook.
getAudiobooksGet Spotify catalog information for several audiobooks identified by their Spotify IDs.
getAudiobookChaptersGet Spotify catalog information about an audiobook's chapters.
getSavedAudiobooksGet a list of the audiobooks saved in the current Spotify user's 'Your Music' library.
saveAudiobooksSave one or more audiobooks to the current Spotify user's library.
removeAudiobooksRemove one or more audiobooks from the Spotify user's library.
checkUserSavedAudiobooksCheck if one or more audiobooks are already saved in the current Spotify user's library.

🔖 Categories

These methods can be accessed through the categories key of your SpotifyClient instance.

MethodDescription
getCategoriesGet a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
getCategoryGet a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).

🕮 Chapters

These methods can be accessed through the chapters key of your SpotifyClient instance.

Note: Chapters are only available for the US, UK, Ireland, New Zealand and Australia markets.

MethodDescription
getChapterGet Spotify catalog information for a single chapter.
getChaptersGet Spotify catalog information for several chapters identified by their Spotify IDs.

🎙️ Episodes

These methods can be accessed through the episodes key of your SpotifyClient instance.

MethodDescription
getEpisodeGet Spotify catalog information for a single episode identified by its unique Spotify ID.
getEpisodesGet Spotify catalog information for several episodes based on their Spotify IDs.
getSavedEpisodesGet a list of the episodes saved in the current Spotify user's library.
saveEpisodesSave one or more episodes to the current user's library.
removeEpisodesRemove one or more episodes from the current user's library.
checkUserSavedEpisodesCheck if one or more episodes is already saved in the current Spotify user's 'Your Episodes' library.

🪩 Genres

These methods can be accessed through the genres key of your SpotifyClient instance.

MethodDescription
getAvailableGenreSeedsRetrieve a list of available genres seed parameter values for recommendations.

🌍 Markets

These methods can be accessed through the genres key of your SpotifyClient instance.

MethodDescription
getMarketsGet the list of markets where Spotify is available.

▶️ Player

These methods can be accessed through the player key of your SpotifyClient instance.

MethodDescription
getPlaybackStateGet information about the user’s current playback state, including track or episode, progress, and active device.
transferPlaybackTransfer playback to a new device and determine if it should start playing.
getAvailableDevicesGet information about a user’s available devices.
getCurrentlyPlayedTrackGet the object currently being played on the user's Spotify account.
startPlaybackStart a new context or resume current playback on the user's active device.
pausePlaybackPause playback on the user's account.
skipToNextSkips to next track in the user’s queue.
skipToPreviousSkips to previous track in the user’s queue.
seekToPositionSeeks to the given position in the user’s currently playing track.
setRepeatModeSet the repeat mode for the user's playback. Options are repeat-track, repeat-context, and off.
setPlaybackVolumeSet the volume for the user’s current playback device.
toggleShuffleToggle shuffle on or off for user’s playback.
getRecentlyPlayedTracksGet tracks from the current user's recently played tracks.
getUserQueueGet the list of objects that make up the user's queue.
addItemToQueueAdd an item to the end of the user's current playback queue.

🎧 Playlists

These methods can be accessed through the playlists key of your SpotifyClient instance.

MethodDescription
getPlaylistGet a playlist owned by a Spotify user.
updatePlaylistDetailsChange a playlist's name and public/private state. (The user must, of course, own the playlist.)
getPlaylistItemsGet full details of the items of a playlist owned by a Spotify user.
updatePlaylistItemsEither reorder or replace items in a playlist depending on the request's parameters. To reorder items, include range_start, insert_before, range_length and snapshot_id in the request's body. To replace items, include uris as either a query parameter or in the request's body. Replacing items in a playlist will overwrite its existing items. This operation can be used for replacing or clearing items in a playlist.
addPlaylistItemsAdd one or more items to a user's playlist.
removePlaylistItemsRemove one or more items from a user's playlist.
getCurrentUserPlaylistsGet a list of the playlists owned or followed by the current Spotify user.
getUserPlaylistsGet a list of the playlists owned or followed by a Spotify user.
createPlaylistCreate a playlist for a Spotify user. (The playlist will be empty until you add tracks.)
getFeaturedPlaylistsGet a list of Spotify featured playlists (shown, for example, on a Spotify player's 'Browse' tab).
getPlaylistsForCategoryGet a list of Spotify playlists tagged with a particular category.
getPlaylistCoverImageGet the current image associated with a specific playlist.
addCustomPlaylistCoverImageReplace the image used to represent a specific playlist.

These methods can be accessed through the search key of your SpotifyClient instance.

Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.

MethodDescription
searchGet Spotify catalog information about albums, artists, playlists, tracks, shows, episodes or audiobooks that match a keyword string.

🎙️ Shows

These methods can be accessed through the shows key of your SpotifyClient instance.

MethodDescription
getShowGet Spotify catalog information for a single show identified by its unique Spotify ID.
getShowsGet Spotify catalog information for several shows based on their Spotify IDs.
getShowsEpisodesGet Spotify catalog information about an show’s episodes. Optional parameters can be used to limit the number of episodes returned.
getSavedShowsGet a list of shows saved in the current Spotify user's library. Optional parameters can be used to limit the number of shows returned.
saveShowsSave one or more shows to current Spotify user's library.
removeShowsDelete one or more shows from current Spotify user's library.
checkUserSavedShowsCheck if one or more shows is already saved in the current Spotify user's library.

🎼 Tracks

These methods can be accessed through the tracks key of your SpotifyClient instance.

MethodDescription
getTrackGet Spotify catalog information for a single track identified by its unique Spotify ID.
getTracksGet Spotify catalog information for multiple tracks based on their Spotify IDs.
getUserSavedTracksGet a list of the songs saved in the current Spotify user's 'Your Music' library.
saveTracksSave one or more tracks to the current user's 'Your Music' library.
removeSavedTracksRemove one or more tracks from the current user's 'Your Music' library.
checkUserSavedTracksCheck if one or more tracks is already saved in the current Spotify user's 'Your Music' library.
getTracksAudioFeaturesGet audio features for multiple tracks based on their Spotify IDs.
getTrackAudioFeaturesGet audio feature information for a single track identified by its unique Spotify ID.
getTrackAudioAnalysisGet a low-level audio analysis for a track in the Spotify catalog. The audio analysis describes the track’s structure and musical content, including rhythm, pitch, and timbre.
getRecommendationsRecommendations are generated based on the available information for a given seed entity and matched against similar artists and tracks. If there is sufficient information about the provided seeds, a list of tracks will be returned together with pool size details.
For artists and tracks that are very new or obscure there might not be enough data to generate a list of tracks.

👥 Users

These methods can be accessed through the users key of your SpotifyClient instance.

MethodDescription
getCurrentUserProfileGet detailed profile information about the current user (including the current user's username).
getCurrentUserTopItemsGet the current user's top artists or tracks based on calculated affinity.
getUserProfileGet public profile information about a Spotify user.
followPlaylistAdd the current user as a follower of a playlist.
unfollowPlaylistRemove the current user as a follower of a playlist.
getFollowedArtistsGet the current user's followed artists.
followAdd the current user as a follower of one or more artists or other Spotify users.
unfollowRemove the current user as a follower of one or more artists or other Spotify users.
isFollowingCheck to see if the current user is following one or more artists or other Spotify users.
isFollowingPlaylistCheck to see if one or more Spotify users are following a specified playlist.

FAQs

Package last updated on 25 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc