// Type definitions for spotify-web-api-node 4.0 // Project: https://github.com/thelinmichael/spotify-web-api-node // Definitions by: Magnar Ovedal Myrtveit // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 /// declare class SpotifyWebApi { constructor(credentials?: Credentials); getCredentials(): Credentials; setCredentials(credentials: Credentials): void; resetCredentials(): void; getClientId(): string | undefined; setClientId(clientId: string): void; resetClientId(): void; getClientSecret(): string | undefined; setClientSecret(clientSecret: string): void; resetClientSecret(): void; getRedirectURI(): string | undefined; setRedirectURI(redirectUri: string): void; resetRedirectURI(): void; getAccessToken(): string | undefined; setAccessToken(accessToken: string): void; resetAccessToken(): void; getRefreshToken(): string | undefined; setRefreshToken(refreshToken: string): void; resetRefreshToken(): void; /** * Look up a track. * @param trackId The track's ID. * @param options The possible options, currently only market. * @param callback Optional callback method to be called instead of the promise. * @example getTrack('3Qm86XLflmIXVm1wcwkgDK').then(...) * @returns A promise that if successful, returns an object containing information * about the track. Not returned if a callback is given. */ getTrack(trackId: string, options: MarketOptions, callback: Callback): void; getTrack(trackId: string, options?: MarketOptions): Promise>; /** * Look up several tracks. * @param trackIds The IDs of the artists. * @param options The possible options, currently only market. * @param callback Optional callback method to be called instead of the promise. * @example getArtists(['0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin']).then(...) * @returns A promise that if successful, returns an object containing information * about the artists. Not returned if a callback is given. */ getTracks(trackIds: ReadonlyArray, options: MarketOptions, callback: Callback): void; getTracks(trackIds: ReadonlyArray, options?: MarketOptions): Promise>; /** * Look up an album. * @param albumId The album's ID. * @param options The possible options, currently only market. * @param callback Optional callback method to be called instead of the promise. * @example getAlbum('0sNOF9WDwhWunNAHPD3Baj').then(...) * @returns A promise that if successful, returns an object containing information * about the album. Not returned if a callback is given. */ getAlbum(albumId: string, options: MarketOptions, callback: Callback): void; getAlbum(albumId: string, options?: MarketOptions): Promise>; /** * Look up several albums. * @param albumIds The IDs of the albums. * @param options The possible options, currently only market. * @param callback Optional callback method to be called instead of the promise. * @example getAlbums(['0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin']).then(...) * @returns A promise that if successful, returns an object containing information * about the albums. Not returned if a callback is given. */ getAlbums(albumIds: ReadonlyArray, options: MarketOptions, callback: Callback): void; getAlbums(albumIds: ReadonlyArray, options?: MarketOptions): Promise>; /** * Look up an artist. * @param artistId The artist's ID. * @param callback Optional callback method to be called instead of the promise. * @example api.getArtist('1u7kkVrr14iBvrpYnZILJR').then(...) * @returns A promise that if successful, returns an object containing information * about the artist. Not returned if a callback is given. */ getArtist(artistId: string, callback: Callback): void; getArtist(artistId: string): Promise>; /** * Look up several artists. * @param artistIds The IDs of the artists. * @param callback Optional callback method to be called instead of the promise. * @example getArtists(['0oSGxfWSnnOXhD2fKuz2Gy', '3dBVyJ7JuOMt4GE9607Qin']).then(...) * @returns A promise that if successful, returns an object containing information * about the artists. Not returned if a callback is given. */ getArtists(artistIds: ReadonlyArray, callback: Callback): void; getArtists(artistIds: ReadonlyArray): Promise>; /** * Search for music entities of certain types. * @param query The search query. * @param types An array of item types to search across. * Valid types are: 'album', 'artist', 'playlist', and 'track'. * @param options The possible options, e.g. limit, offset. * @param callback Optional callback method to be called instead of the promise. * @example search('Abba', ['track', 'playlist'], { limit : 5, offset : 1 }).then(...) * @returns 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. */ search(query: string, types: ReadonlyArray, options: SearchOptions, callback: Callback): void; search(query: string, types: ReadonlyArray, options?: SearchOptions): Promise>; /** * Search for an album. * @param query The search query. * @param options The possible options, e.g. limit, offset. * @param callback Optional callback method to be called instead of the promise. * @example searchAlbums('Space Oddity', { limit : 5, offset : 1 }).then(...) * @returns 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. */ searchAlbums(query: string, options: SearchOptions, callback: Callback): void; searchAlbums(query: string, options?: SearchOptions): Promise>; /** * Search for an artist. * @param query The search query. * @param options The possible options, e.g. limit, offset. * @param callback Optional callback method to be called instead of the promise. * @example searchArtists('David Bowie', { limit : 5, offset : 1 }).then(...) * @returns 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. */ searchArtists(query: string, options: SearchOptions, callback: Callback): void; searchArtists(query: string, options?: SearchOptions): Promise>; /** * Search for a track. * @param query The search query. * @param options The possible options, e.g. limit, offset. * @param callback Optional callback method to be called instead of the promise. * @example searchTracks('Mr. Brightside', { limit : 3, offset : 2 }).then(...) * @returns 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. */ searchTracks(query: string, options: SearchOptions, callback: Callback): void; searchTracks(query: string, options?: SearchOptions): Promise>; /** * Search for playlists. * @param query The search query. * @param options The possible options. * @param callback Optional callback method to be called instead of the promise. * @example searchPlaylists('workout', { limit : 1, offset : 0 }).then(...) * @returns 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. */ searchPlaylists(query: string, options: SearchOptions, callback: Callback): void; searchPlaylists(query: string, options?: SearchOptions): Promise>; /** * Get an artist's albums. * @param artistId The artist's ID. * @param options The possible options, e.g. limit, offset. * @param 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 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. */ getArtistAlbums(artistId: string, options: GetArtistAlbumsOptions, callback: Callback): void; getArtistAlbums(artistId: string, options?: GetArtistAlbumsOptions): Promise>; /** * Get the tracks of an album. * @param albumId the album's ID. * @param options The possible options, e.g. limit. * @param callback Optional callback method to be called instead of the promise. * @example getAlbumTracks('41MnTivkwTO3UUJ8DrqEJJ', { limit : 5, offset : 1 }).then(...) * @returns 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. */ getAlbumTracks(albumId: string, options: PaginationMarketOptions, callback: Callback): void; getAlbumTracks(albumId: string, options?: PaginationMarketOptions): Promise>; /** * Get an artist's top tracks. * @param artistId The artist's ID. * @param country The country/territory where the tracks are most popular. (format: ISO 3166-1 alpha-2) * @param callback Optional callback method to be called instead of the promise. * @example getArtistTopTracks('0oSGxfWSnnOXhD2fKuz2Gy', 'GB').then(...) * @returns 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. */ getArtistTopTracks(artistId: string, country: string, callback: Callback): void; getArtistTopTracks(artistId: string, country: string): Promise>; /** * Get related artists. * @param artistId The artist's ID. * @param callback Optional callback method to be called instead of the promise. * @example getArtistRelatedArtists('0oSGxfWSnnOXhD2fKuz2Gy').then(...) * @returns 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. */ getArtistRelatedArtists(artistId: string, callback: Callback): void; getArtistRelatedArtists(artistId: string): Promise>; /** * Get information about a user. * @param userId The user ID. * @param callback Optional callback method to be called instead of the promise. * @example getUser('thelinmichael').then(...) * @returns 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. */ getUser(userId: string, callback: Callback): void; getUser(userId: string): Promise>; /** * Get information about the user that has signed in (the current user). * @param callback Optional callback method to be called instead of the promise. * @example getMe().then(...) * @returns 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. */ getMe(callback: Callback): void; getMe(): Promise>; /** * Get a user's playlists. * @param userId An optional id of the user. If you know the Spotify URI it is easy * to find the id (e.g. spotify:user:). If not provided, the id of the user that granted * the permissions will be used. * @param options The options supplied to this request. * @param callback Optional callback method to be called instead of the promise. * @example getUserPlaylists('thelinmichael').then(...) * @returns 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. */ getUserPlaylists(userId: string, options: PaginationOptions, callback: Callback): void; getUserPlaylists(options: PaginationOptions, callback: Callback): void; getUserPlaylists(userId: string, options?: PaginationOptions): Promise>; getUserPlaylists(options?: PaginationOptions): Promise>; /** * Get a playlist. * @param playlistId The playlist's ID. * @param options The options supplied to this request. * @param callback Optional callback method to be called instead of the promise. * @example getPlaylist('3EsfV6XzCHU8SPNdbnFogK').then(...) * @returns 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. */ getPlaylist(playlistId: string, options: GetPlaylistOptions, callback: Callback): void; getPlaylist(playlistId: string, options?: GetPlaylistOptions): Promise>; /** * Get tracks in a playlist. * @param playlistId The playlist's ID. * @param options Optional options, such as fields. * @param callback Optional callback method to be called instead of the promise. * @example getPlaylistTracks('3ktAYNcRHpazJ9qecm3ptn').then(...) * @returns 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. */ getPlaylistTracks(playlistId: string, options: GetPlaylistTracksOptions, callback: Callback): void; getPlaylistTracks(playlistId: string, options?: GetPlaylistTracksOptions): Promise>; /** * Create a playlist. * @param userId The playlist's owner's user ID. * @param playlistName The name of the playlist. * @param options The possible options, currently only public. * @param callback Optional callback method to be called instead of the promise. * @example createPlaylist('thelinmichael', 'My cool playlist!', { public : false }).then(...) * @returns 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. */ createPlaylist(userId: string, playlistName: string, options: PlaylistDetailsOptions, callback: Callback): void; createPlaylist(userId: string, playlistName: string, options?: PlaylistDetailsOptions): Promise>; /** * Follow a playlist. * @param playlistId The playlist's ID * @param options The possible options, currently only public. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ followPlaylist(playlistId: string, options: PublicOptions, callback: Callback): void; followPlaylist(playlistId: string, options?: PublicOptions): Promise>; /** * Unfollow a playlist. * @param playlistId The playlist's ID * @param options The possible options, currently only public. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ unfollowPlaylist(playlistId: string, callback: Callback): void; unfollowPlaylist(playlistId: string): Promise>; /** * Change playlist details. * @param playlistId The playlist's ID * @param options The possible options, e.g. name, public. * @param callback Optional callback method to be called instead of the promise. * @example changePlaylistDetails('3EsfV6XzCHU8SPNdbnFogK', {name: 'New name', public: true}).then(...) * @returns 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. */ changePlaylistDetails(playlistId: string, options: ChangePlaylistOptions, callback: Callback): void; changePlaylistDetails(playlistId: string, options?: ChangePlaylistOptions): Promise>; /** * Replace the image used to represent a specific playlist. * @param playlistId The playlist's ID * @param base64URI Base64 encoded JPEG image data, maximum payload size is 256 KB * @param callback Optional callback method to be called instead of the promise. * @example uploadCustomPlaylistCoverImage('3EsfV6XzCHU8SPNdbnFogK', 'longbase64uri').then(...) * @returns 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. */ uploadCustomPlaylistCoverImage(playlistId: string, base64URI: string, callback: Callback): void; uploadCustomPlaylistCoverImage(playlistId: string, base64URI: string): Promise>; /** * Add tracks to a playlist. * @param playlistId The playlist's ID * @param tracks URIs of the tracks to add to the playlist. * @param options Options, position being the only one. * @param callback Optional callback method to be called instead of the promise. * @example addTracksToPlaylist(3EsfV6XzCHU8SPNdbnFogK', ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"]).then(...) * @returns 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. */ addTracksToPlaylist(playlistId: string, tracks: ReadonlyArray, options: PositionOptions, callback: Callback): void; addTracksToPlaylist(playlistId: string, tracks: ReadonlyArray, options?: PositionOptions): Promise>; /** * Remove tracks from a playlist. * @param playlistId The playlist's ID * @param tracks 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] } * @param options Options, snapshot_id being the only one. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ removeTracksFromPlaylist(playlistId: string, tracks: ReadonlyArray, options: SnapshotOptions, callback: Callback): void; removeTracksFromPlaylist(playlistId: string, tracks: ReadonlyArray, options?: SnapshotOptions): Promise>; /** * Remove tracks from a playlist by position instead of specifying the tracks' URIs. * @param playlistId The playlist's ID * @param positions The positions of the tracks in the playlist that should be removed * @param snapshot_id The snapshot ID, or version, of the playlist. Required * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ removeTracksFromPlaylistByPosition(playlistId: string, positions: ReadonlyArray, snapshotId: string, callback: Callback): void; removeTracksFromPlaylistByPosition(playlistId: string, positions: ReadonlyArray, snapshotId: string): Promise>; /** * Replace tracks in a playlist. * @param playlistId The playlist's ID * @param uris An array of track URIs (strings) * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful returns an empty object. If rejected, * it contains an error object. Not returned if a callback is given. */ replaceTracksInPlaylist(playlistId: string, uris: ReadonlyArray, callback: Callback): void; replaceTracksInPlaylist(playlistId: string, uris: ReadonlyArray): Promise>; /** * Reorder tracks in a playlist. * @param playlistId The playlist's ID * @param rangeStart The position of the first track to be reordered. * @param insertBefore The position where the tracks should be inserted. * @param options Optional parameters, i.e. range_length and snapshot_id. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ reorderTracksInPlaylist(playlistId: string, rangeStart: number, insertBefore: number, options: ReorderPlaylistTracksOptions, callback: Callback): void; reorderTracksInPlaylist(playlistId: string, rangeStart: number, insertBefore: number, options?: ReorderPlaylistTracksOptions): Promise>; /** * Get audio features for a single track identified by its unique Spotify ID. * @param trackId The track ID * @param callback Optional callback method to be called instead of the promise. * @example getAudioFeaturesForTrack('38P3Q4QcdjQALGF2Z92BmR').then(...) * @returns 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. */ getAudioFeaturesForTrack(trackId: string, callback: Callback): void; getAudioFeaturesForTrack(trackId: string): Promise>; /** * Get audio analysis for a single track identified by its unique Spotify ID. * @param trackId The track ID * @param callback Optional callback method to be called instead of the promise. * @example getAudioAnalysisForTrack('38P3Q4QcdjQALGF2Z92BmR').then(...) * @returns A promise that if successful, resolves to an object * containing information about the audio analysis. If the promise is * rejected, it contains an error object. Not returned if a callback is given. */ getAudioAnalysisForTrack(trackId: string, callback: Callback): void; getAudioAnalysisForTrack(trackId: string): Promise>; /** * Get audio features for multiple tracks identified by their unique Spotify ID. * @param trackIds The track IDs * @param callback Optional callback method to be called instead of the promise. * @example getAudioFeaturesForTracks(['38P3Q4QcdjQALGF2Z92BmR', '2HO2bnoMrpnZUbUqiilLHi']).then(...) * @returns 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. */ getAudioFeaturesForTracks(trackIds: ReadonlyArray, callback: Callback): void; getAudioFeaturesForTracks(trackIds: ReadonlyArray): Promise>; /** * Create a playlist-style listening experience based on seed artists, tracks and genres. * @param options The options supplied to this request. * @param 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 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. */ getRecommendations(options: GetRecommendationsOptions, callback: Callback): void; getRecommendations(options?: GetRecommendationsOptions): Promise>; /** * Retrieve a URL where the user can give the application permissions. * @param scopes The scopes corresponding to the permissions the application needs. * @param state 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. * @param showDialog A parameter that you can use to force the user to approve the app on each login rather than being automatically redirected. * @returns The URL where the user can give application permissions. */ createAuthorizeURL(scopes: ReadonlyArray, state: string, showDialog?: boolean): string; /** * Retrieve the tracks that are saved to the authenticated users Your Music library. * @param options Options, being market, limit, and/or offset. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ getMySavedTracks(options: PaginationMarketOptions, callback: Callback): void; getMySavedTracks(options?: PaginationMarketOptions): Promise>; /** * Check if one or more tracks is already saved in the current Spotify user’s “Your Music” library. * @param trackIds The track IDs * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ containsMySavedTracks(trackIds: ReadonlyArray, callback: Callback): void; containsMySavedTracks(trackIds: ReadonlyArray): Promise>; /** * Remove a track from the authenticated user's Your Music library. * @param trackIds The track IDs * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful returns null, otherwise an error. * Not returned if a callback is given. */ removeFromMySavedTracks(trackIds: ReadonlyArray, callback: Callback): void; removeFromMySavedTracks(trackIds: ReadonlyArray): Promise>; /** * Add a track from the authenticated user's Your Music library. * @param trackIds The track IDs * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful returns null, otherwise an error. Not returned if a callback is given. */ addToMySavedTracks(trackIds: ReadonlyArray, callback: Callback): void; addToMySavedTracks(trackIds: ReadonlyArray): Promise>; /** * Remove an album from the authenticated user's Your Music library. * @param albumIds The album IDs * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful returns null, otherwise an error. * Not returned if a callback is given. */ removeFromMySavedAlbums(albumIds: ReadonlyArray, callback: Callback): void; removeFromMySavedAlbums(albumIds: ReadonlyArray): Promise>; /** * Add an album from the authenticated user's Your Music library. * @param albumIds The track IDs * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful returns null, otherwise an error. Not returned if a callback is given. */ addToMySavedAlbums(albumIds: ReadonlyArray, callback: Callback): void; addToMySavedAlbums(albumIds: ReadonlyArray): Promise>; /** * Retrieve the albums that are saved to the authenticated users Your Music library. * @param options Options, being market, limit, and/or offset. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ getMySavedAlbums(options: PaginationMarketOptions, callback: Callback): void; getMySavedAlbums(options?: PaginationMarketOptions): Promise>; /** * Check if one or more albums is already saved in the current Spotify user’s “Your Music” library. * @param albumIds The album IDs * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ containsMySavedAlbums(albumIds: ReadonlyArray, callback: Callback): void; containsMySavedAlbums(albumIds: ReadonlyArray): Promise>; /** * Get the current user's top artists based on calculated affinity. * @param options Options, being time_range, limit, offset. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of artists, * otherwise an error. Not returned if a callback is given. */ getMyTopArtists(options: GetTopOptions, callback: Callback): void; getMyTopArtists(options?: GetTopOptions): Promise>; /** * Get the current user's top tracks based on calculated affinity. * @param options Options, being time_range, limit, offset. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ getMyTopTracks(options: GetTopOptions, callback: Callback): void; getMyTopTracks(options?: GetTopOptions): Promise>; /** * Get the Current User's Recently Played Tracks * @param options Options, being type, after, limit, before. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ getMyRecentlyPlayedTracks(options: BeforeOptions | AfterOptions, callback: Callback): void; getMyRecentlyPlayedTracks(options?: BeforeOptions | AfterOptions): Promise>; /** * Get the Current User's Connect Devices * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ getMyDevices(callback: Callback): void; getMyDevices(): Promise>; /** * Get the Current User's Currently Playing Track. * @param options Options, being market. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ getMyCurrentPlayingTrack(options: MarketOptions, callback: Callback): void; getMyCurrentPlayingTrack(options?: MarketOptions): Promise>; /** * Get the Current User's Current Playback State * @param options Options, being market. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ getMyCurrentPlaybackState(options: MarketOptions, callback: Callback): void; getMyCurrentPlaybackState(options?: MarketOptions): Promise>; /** * Transfer a User's Playback * @param options Options, being market. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ transferMyPlayback(options: TransferPlaybackOptions, callback: Callback): void; transferMyPlayback(options?: TransferPlaybackOptions): Promise>; /** * Starts or Resumes the Current User's Playback * @param options Options, being device_id, context_uri, offset, uris. * @param callback Optional callback method to be called instead of the promise. * @example playbackResume({context_uri: 'spotify:album:5ht7ItJgpBH7W6vJ5BqpPr'}).then(...) * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ play(options: PlayOptions, callback: Callback): void; play(options?: PlayOptions): Promise>; /** * Pauses the Current User's Playback * @param options Options, for now device_id, * @param callback Optional callback method to be called instead of the promise. * @example playbackPause().then(...) * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ pause(options: DeviceOptions, callback: Callback): void; pause(options?: DeviceOptions): Promise>; /** * Skip the Current User's Playback To Previous Track * @param callback Optional callback method to be called instead of the promise. * @example playbackPrevious().then(...) * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ skipToPrevious(callback: Callback): void; skipToPrevious(): Promise>; /** * Skip the Current User's Playback To Next Track * @param callback Optional callback method to be called instead of the promise. * @example playbackNext().then(...) * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ skipToNext(callback: Callback): void; skipToNext(): Promise>; /** * Seeks to the given position in the user’s currently playing track. * * @param positionMs The position in milliseconds to seek to. Must be a positive number. * @param options A JSON object with options that can be passed. * @param callback An optional callback that receives 2 parameters. The first * one is the error object (null if no error), and the second is the value if the request succeeded. * @returns Null if a callback is provided, a Promise otherwise */ seek(positionMs: number, options: DeviceOptions, callback: Callback): void; seek(positionMs: number, options?: DeviceOptions): Promise>; /** * Set Repeat Mode On The Current User's Playback * @param options Options, being state (track, context, off). * @param callback Optional callback method to be called instead of the promise. * @example playbackRepeat({state: 'context'}).then(...) * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ setRepeat(options: RepeatOptions, callback: Callback): void; setRepeat(options?: RepeatOptions): Promise>; /** * Set Shuffle Mode On The Current User's Playback * @param options Options, being state (true, false). * @param callback Optional callback method to be called instead of the promise. * @example playbackShuffle({state: 'false'}).then(...) * @returns A promise that if successful, resolves into a paging object of tracks, * otherwise an error. Not returned if a callback is given. */ setShuffle(options: ShuffleOptions, callback: Callback): void; setShuffle(options?: ShuffleOptions): Promise>; /** * Set the volume for the user’s current playback device. * * @param volumePercent The volume to set. Must be a value from 0 to 100 inclusive. * @param options A JSON object with options that can be passed. * @param callback An optional callback that receives 2 parameters. The first * one is the error object (null if no error), and the second is the value if the request succeeded. * @returns nothing if callback is provided, a Promise otherwise */ setVolume(volumePercent: number, options: DeviceOptions, callback: Callback): void; setVolume(volumePercent: number, options?: DeviceOptions): Promise>; /** * Add the current user as a follower of one or more other Spotify users. * @param userIds The IDs of the users to be followed. * @param callback Optional callback method to be called instead of the promise. * @example followUsers(['thelinmichael', 'wizzler']).then(...) * @returns 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. */ followUsers(userIds: ReadonlyArray, callback: Callback): void; followUsers(userIds: ReadonlyArray): Promise>; /** * Add the current user as a follower of one or more artists. * @param artistIds The IDs of the artists to be followed. * @param callback Optional callback method to be called instead of the promise. * @example followArtists(['0LcJLqbBmaGUft1e9Mm8HV', '3gqv1kgivAc92KnUm4elKv']).then(...) * @returns 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. */ followArtists(artistIds: ReadonlyArray, callback: Callback): void; followArtists(artistIds: ReadonlyArray): Promise>; /** * Remove the current user as a follower of one or more other Spotify users. * @param userIds The IDs of the users to be unfollowed. * @param callback Optional callback method to be called instead of the promise. * @example unfollowUsers(['thelinmichael', 'wizzler']).then(...) * @returns 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. */ unfollowUsers(userIds: ReadonlyArray, callback: Callback): void; unfollowUsers(userIds: ReadonlyArray): Promise>; /** * Remove the current user as a follower of one or more artists. * @param artistIds The IDs of the artists to be unfollowed. * @param callback Optional callback method to be called instead of the promise. * @example unfollowArtists(['0LcJLqbBmaGUft1e9Mm8HV', '3gqv1kgivAc92KnUm4elKv']).then(...) * @returns 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. */ unfollowArtists(artistIds: ReadonlyArray, callback: Callback): void; unfollowArtists(artistIds: ReadonlyArray): Promise>; /** * Check to see if the current user is following one or more other Spotify users. * @param userIds The IDs of the users to check if are followed by the current user. * @param callback Optional callback method to be called instead of the promise. * @example isFollowingUsers(['thelinmichael', 'wizzler']).then(...) * @returns 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. */ isFollowingUsers(userIds: ReadonlyArray, callback: Callback): void; isFollowingUsers(userIds: ReadonlyArray): Promise>; /** * Get the current user's followed artists. * @param options Options, being after and limit. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves to an object containing a paging object which contains * album objects. Not returned if a callback is given. */ getFollowedArtists(options: AfterOptions, callback: Callback): void; getFollowedArtists(options?: AfterOptions): Promise>; /** * Check if users are following a playlist. * @param userId The playlist's owner's user ID * @param playlistId The playlist's ID * @param User IDs of the following users * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful returns an array of booleans. If rejected, * it contains an error object. Not returned if a callback is given. */ areFollowingPlaylist(userId: string, playlistId: string, followerIds: ReadonlyArray, callback: Callback): void; areFollowingPlaylist(userId: string, playlistId: string, followerIds: ReadonlyArray): Promise>; /** * Check to see if the current user is following one or more artists. * @param artistIds The IDs of the artists to check if are followed by the current user. * @param callback Optional callback method to be called instead of the promise. * @example isFollowingArtists(['0LcJLqbBmaGUft1e9Mm8HV', '3gqv1kgivAc92KnUm4elKv']).then(...) * @returns 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. */ isFollowingArtists(artistIds: ReadonlyArray, callback: Callback): void; isFollowingArtists(artistIds: ReadonlyArray): Promise>; /** * Retrieve new releases * @param options Options, being country, limit and/or offset. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves to an object containing a paging object which contains * album objects. Not returned if a callback is given. */ getNewReleases(options: PaginationCountryOptions, callback: Callback): void; getNewReleases(options?: PaginationCountryOptions): Promise>; /** * Retrieve featured playlists * @param options Options, being country, locale, timestamp, limit, offset. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves to an object containing a paging object which contains * featured playlists. Not returned if a callback is given. */ getFeaturedPlaylists(options: GetFeaturedPlaylistsOptions, callback: Callback): void; getFeaturedPlaylists(options?: GetFeaturedPlaylistsOptions): Promise>; /** * Retrieve a list of categories used to tag items in Spotify (e.g. in the 'Browse' tab) * @param options Options, being country, locale, limit, offset. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves to an object containing a paging object of categories. * Not returned if a callback is given. */ getCategories(options: PaginationLocaleOptions, callback: Callback): void; getCategories(options?: PaginationLocaleOptions): Promise>; /** * Retrieve a category. * @param categoryId The id of the category to retrieve. * @param options Options, being country, locale. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves to an object containing a category object. * Not returned if a callback is given. */ getCategory(categoryId: string, options: LocaleOptions, callback: Callback): void; getCategory(categoryId: string, options?: LocaleOptions): Promise>; /** * Retrieve playlists for a category. * @param categoryId The id of the category to retrieve playlists for. * @param options Options, being country, limit, offset. * @param callback Optional callback method to be called instead of the promise. * @returns A promise that if successful, resolves to a paging object containing simple playlists. * Not returned if a callback is given. */ getPlaylistsForCategory(categoryId: string, options: PaginationCountryOptions, callback: Callback): void; getPlaylistsForCategory(categoryId: string, options?: PaginationCountryOptions): Promise>; /** * Request an access token using the Client Credentials flow. * Requires that client ID and client secret has been set previous to the call. * @param options Options. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ clientCredentialsGrant(options: {}, callback: Callback): void; clientCredentialsGrant(options?: {}): Promise>; /** * 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. * @param code The authorization code returned in the callback in the Authorization Code flow. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ authorizationCodeGrant(code: string, callback: Callback): void; authorizationCodeGrant(code: string): Promise>; /** * 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. * @param callback Optional callback method to be called instead of the promise. * @returns 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. */ refreshAccessToken(callback: Callback): void; refreshAccessToken(): Promise>; } type Callback = (error: Error, response: Response) => void; interface Response { body: T; headers: Record; statusCode: number; } interface Credentials { accessToken?: string; clientId?: string; clientSecret?: string; redirectUri?: string; refreshToken?: string; } interface Track { positions?: ReadonlyArray; uri: string; } interface LimitOptions { limit?: number; } interface PaginationOptions extends LimitOptions { offset?: number; } interface DeviceOptions { device_id?: string; } interface MarketOptions { market?: string; } interface FieldsOptions { fields?: string; } interface PublicOptions { public?: boolean; } interface SnapshotOptions { snapshot_id?: string; } interface CountryOptions { country?: string; } interface BeforeOptions extends LimitOptions { before?: number; } interface AfterOptions extends LimitOptions { after?: number; } interface LocaleOptions extends CountryOptions { locale?: string; } interface PaginationMarketOptions extends PaginationOptions, MarketOptions { } interface PaginationCountryOptions extends PaginationOptions, CountryOptions { } interface PaginationLocaleOptions extends PaginationOptions, LocaleOptions { } interface GetPlaylistOptions extends MarketOptions, FieldsOptions { } interface PlaylistDetailsOptions extends PublicOptions { collaborative?: boolean; description?: string; } interface ChangePlaylistOptions extends PlaylistDetailsOptions { name?: string; } interface PositionOptions { position?: number; } interface GetArtistAlbumsOptions extends PaginationCountryOptions { include_groups?: string; } interface GetPlaylistTracksOptions extends PaginationMarketOptions, FieldsOptions { } type SearchType = 'album' | 'artist' | 'playlist' | 'track'; interface SearchOptions extends PaginationMarketOptions { include_external?: 'audio'; } interface ReorderPlaylistTracksOptions extends SnapshotOptions { range_length?: number; } interface GetRecommendationsOptions extends LimitOptions, MarketOptions { max_acousticness?: number; max_danceability?: number; max_duration_ms?: number; max_energy?: number; max_instrumentalness?: number; max_key?: number; max_liveness?: number; max_loudness?: number; max_mode?: number; max_popularity?: number; max_speechiness?: number; max_tempo?: number; max_time_signature?: number; max_valence?: number; min_acousticness?: number; min_danceability?: number; min_duration_ms?: number; min_energy?: number; min_instrumentalness?: number; min_key?: number; min_liveness?: number; min_loudness?: number; min_mode?: number; min_popularity?: number; min_speechiness?: number; min_tempo?: number; min_time_signature?: number; min_valence?: number; seed_artists?: ReadonlyArray | string; seed_genres?: ReadonlyArray | string; seed_tracks?: ReadonlyArray | string; target_acousticness?: number; target_danceability?: number; target_duration_ms?: number; target_energy?: number; target_instrumentalness?: number; target_key?: number; target_liveness?: number; target_loudness?: number; target_mode?: number; target_popularity?: number; target_speechiness?: number; target_tempo?: number; target_time_signature?: number; target_valence?: number; } interface GetTopOptions extends PaginationOptions { time_range?: 'long_term' | 'medium_term' | 'short_term'; } interface TransferPlaybackOptions { device_ids: ReadonlyArray; play?: boolean; } interface PlayOptions extends DeviceOptions { context_uri?: string; uris?: ReadonlyArray; offset?: { position: number } | { uri: string }; position_ms?: number; } interface RepeatOptions extends DeviceOptions { state?: 'track' | 'context' | 'off'; } interface ShuffleOptions extends DeviceOptions { state?: boolean; } interface GetFeaturedPlaylistsOptions extends PaginationLocaleOptions { timestamp?: string; } /** * Response returned when using Client Credentials authentication flow * https://developer.spotify.com/documentation/general/guides/authorization-guide/#example-4 */ interface ClientCredentialsGrantResponse { access_token: string; expires_in: number; token_type: string; } /** * Response returned when requesting for access token * https://developer.spotify.com/documentation/general/guides/authorization-guide/#2-have-your-application-request-refresh-and-access-tokens-spotify-returns-access-and-refresh-tokens */ interface AuthorizationCodeGrantResponse { access_token: string; expires_in: number; refresh_token: string; scope: string; token_type: string; } /** * Response returned when requesting new access token (via refresh token) * https://developer.spotify.com/documentation/general/guides/authorization-guide/#4-requesting-a-refreshed-access-token-spotify-returns-a-new-access-token-to-your-app */ interface RefreshAccessTokenResponse { access_token: string; expires_in: number; scope: string; token_type: string; } export = SpotifyWebApi;