- Search API
- Browse API
- Albums API
- Artists API
- Tracks API
- Shows API
- Episodes API
- User API
- Markets API
Using NPM:
npm install --save spotifyx
Using Yarn:
yarn add spotifyx
CommonJS
const Spotify = require("spotifyx");
ES6
import Spotify from "spotifyx";
import Spotify from "spotifyx";
(async () => {
const client = new Spotify({
clientId: "a-cool-id",
clientSecret: "a-cool-secret",
});
await client.login();
console.log(await client.search("Null Magma", ["artist"]));
})();
Key:
- π² β Class declaration
- πΏ β Property
- πΌ β Method
Most typedefs are from Spotify's documentation.
π² Spotify
Constructs a new Spotify API client.
credentials
β Client credentials to log inclientId
β Client IDclientSecret
β Client secretredirectUrl?
β URL to redirect to
Spotify
β The newly created client
const client = new Spotify({
clientId: "a-cool-id",
clientSecret: "a-cool-secret",
});
readonly string
The client's current access token
Browser
The client's Spotify browse API
Artists
The client's Spotify artists API
Albums
The client's Spotify albums API
Tracks
The client's Spotify tracks API
Episodes
The client's Spotify episodes API
Shows
The client's Spotify shows API
Logs the client in and creates an access token.
string
β The newly created access token
await client.login();
Searches Spotify using Spotify's search API.
query
β Search querytypes
β Object types to search foroptions?
β Search optionsmarket?
β Market to search withinlimit?
β Search results limitoffset?
β Search results offsetincludeExternal?
β Include externals in results
SearchResponse
β Search results
const results = await client.search("Null Magma", ["artist"]);
Obtains a user from Spotify using an ID.
id
β The user's ID
PublicUserObject?
β User obtained from the user ID, or undefined if no user was found
const user = await client.user("a-cool-id");
Gets all the markets.
string[]
β All markets
const markets = await client.markets();
π² Browser
Wrapper for Spotify's browse API.
private
Fetches newest releases.
options?
β Fetch optionscountry?
β Country codelimit?
β Fetch limitoffset?
β Fetch offset
BrowseNewReleasesResponse
β Fetched new releases
const releases = await client.browse.newReleases({
limit: 25,
offset: 25,
});
Fetches featured playlists.
options?
β Fetch optionscountry?
β Country codelocale?
β Localetimestamp?
β Timestamplimit?
β Fetch limitoffset?
β Fetch offset
BrowseFeaturedPlaylistsResponse
β Fetched featured playlists
const playlists = await client.browse.featuredPlaylists();
Fetches all categories.
options?
β Fetch optionscountry?
β Country codelocale?
β Localelimit?
β Fetch limitoffset?
β Fetch offset
BrowseAllCategoriesResponse
β Fetched categories
const categories = await client.browse.allCategories();
Fetches a category.
category
β The categoryoptions?
β Fetch optionscountry?
β Country codelocale?
β Locale
BrowseCategoryResponse
β Fetched categories
const category = await client.browse.category("party");
Fetches a category's playlists.
category
β The categoryoptions?
β Fetch optionscountry?
β Country code
limit?
β Fetch limitoffset?
β Fetch offset
PagingObject<SimplifiedPlaylistObject>
β Fetched playlists
const playlists = await client.browse.categoryPlaylists("party");
Fetches a category's playlists.
seeds
β Seedsartists
β Seed artistsgenres
β Seed genrestracks
- Seed tracks
options?
β Fetch options- Not available
BrowseRecommendationsResponse
β Fetched category platlists
Not available
Fetches recommendation genres.
string[]
β Fetched genres
const genres = await client.browse.recommendationGenres();
π² Artists
Wrapper for Spotify's artists API.
private
Retrieves an artist or multiple artists.
ids
β Can either be an ID or array of IDs.
If a single ID is used:
ArtistsSingleArtistResponse
β The artist retrieved
If an array of IDs is used:
ArtistsMultipleArtistsResponse
β The artists retrieved
const artists = await client.artists.get(["a-id", "another-id"]);
Retrieves an artist's top tracks.
id
β Artist ID
ArtistsTopTracksResponse
β The artist's top tracks
const topTracks = await client.artists.topTracks("an-id");
Retrieves an artist's related artists.
id
β Artist ID
ArtistsRelatedArtistsResponse
β The artist's related artists
const related = await client.artists.related("an-id");
Retrieves an artist's albums.
id
β Artist ID
ArtistsAlbumsResponse
β The artist's albums
const albums = await client.artists.albums("an-id");
π² Albums
Wrapper for Spotify's shows API.
private
Retrieves an album or multiple albums.
ids
β Can either be an ID or array of IDs.options?
β Fetch optionsmarket?
β Country code
If a single ID is used:
AlbumsSingleAlbumResponse
β The album retrieved
If an array of IDs is used:
AlbumsMultipleAlbumsResponse
β The albums retrieved
const albums = await client.albums.get(["an-id", "another-id"]);
Retrieves an album's tracks.
id
β The album's IDoptions?
β Fetch optionsmarket
β Country codelimit
β Fetch limitoffset
β Fetch offset
AlbumsTracksResponse
β The album's tracks
const tracks = await client.albums.tracks("an-id");
π² Tracks
Wrapper for Spotify's tracks API.
private
Retrieves a track or multiple tracks.
ids
β Can either be an ID or array of IDs.options?
β Fetch optionsmarket?
β Country code
If a single ID is used:
TracksSingleTrackResponse
β The track retrieved
If an array of IDs is used:
TracksMultipleTracksResponse
β The tracks retrieved
Retrieves a track or multiple tracks' audio features.
ids
β Can either be an ID or array of IDs.options?
β Fetch optionsmarket?
β Country code
If a single ID is used:
TracksSingleTrackAudioFeatureResponse
β The audio feature retrieved
If an array of IDs is used:
TracksMultipleTracksAudioFeaturesResponse
β The audio features retrieved
Retrieves a track's audio analysis
id
β Track ID
AudioAnalysisObject
β The audio analysis
π² Episodes
Wrapper for Spotify's episodes API.
private
Retrieves an episode or multiple episodes.
ids
β Can either be an ID or array of IDs.options?
β Fetch optionsmarket?
β Country code
If a single ID is used:
EpisodesSingleEpisodeResponse
β The episode retrieved
If an array of IDs is used:
EpisodesMultipleEpisodesResponse
β The episodes retrieved
π² Shows
Wrapper for Spotify's shows API.
private
Retrieves a show or multiple shows.
ids
β Can either be an ID or array of IDs.options?
β Fetch optionsmarket?
β Country code
If a single ID is used:
ShowsSingleShowResponse
β The show retrieved
If an array of IDs is used:
ShowsMultipleShowsResponse
β The shows retrieved
const shows = await client.shows.get(["an-id", "another-id"]);
Retrieves a show's episodes.
id
β The show's ID
ShowsEpisodesResponse
β The episodes retrieved
const episodes = await client.shows.episodes("an-id");
- Include other three authorization flows
- Use refresh tokens
- Spotify user auth service
- Authorization scopes
- Access to user-related APIs
- Access to other APIs