Skip to content

SpotifyApi

Constructors

new SpotifyApi()

new SpotifyApi(authentication, config?): SpotifyApi

Parameters

authentication: IAuthStrategy

config?: SdkOptions

Returns

SpotifyApi

Source

SpotifyApi.ts:59

Properties

albums

albums: default

Source

SpotifyApi.ts:42


artists

artists: default

Source

SpotifyApi.ts:43


audiobooks

audiobooks: default

Source

SpotifyApi.ts:44


browse

browse: default

Source

SpotifyApi.ts:45


chapters

chapters: default

Source

SpotifyApi.ts:46


currentUser

currentUser: default

Source

SpotifyApi.ts:57


episodes

episodes: default

Source

SpotifyApi.ts:47


markets

markets: default

Source

SpotifyApi.ts:49


player

player: default

Source

SpotifyApi.ts:50


playlists

playlists: default

Source

SpotifyApi.ts:51


recommendations

recommendations: default

Source

SpotifyApi.ts:48


search: SearchExecutionFunction

Source

SpotifyApi.ts:55


shows

shows: default

Source

SpotifyApi.ts:52


tracks

tracks: default

Source

SpotifyApi.ts:53


users

users: default

Source

SpotifyApi.ts:54

Methods

authenticate()

authenticate(): Promise<AuthenticationResponse>

Use this when you’re running in a browser and you want to control when first authentication+redirect happens.

Returns

Promise<AuthenticationResponse>

Source

SpotifyApi.ts:162


getAccessToken()

getAccessToken(): Promise<null | AccessToken>

Returns

Promise<null | AccessToken>

the current access token. null implies the SpotifyApi is not yet authenticated.

Source

SpotifyApi.ts:175


logOut()

logOut(): Promise<void>

Removes the access token if it exists.

Returns

Promise<void>

Source

SpotifyApi.ts:182


makeRequest()

makeRequest<TReturnType>(method, url, body, contentType): Promise<TReturnType>

Type parameters

TReturnType

Parameters

method: "GET" | "POST" | "PUT" | "DELETE"

url: string

body: any= undefined

contentType: undefined | string= undefined

Returns

Promise<TReturnType>

Source

SpotifyApi.ts:84


switchAuthenticationStrategy()

switchAuthenticationStrategy(authentication): void

Parameters

authentication: IAuthStrategy

Returns

void

Source

SpotifyApi.ts:153


performUserAuthorization()

performUserAuthorization(clientId, redirectUri, scopes, postbackUrl, config)

static performUserAuthorization(clientId, redirectUri, scopes, postbackUrl, config?): Promise<AuthenticationResponse>

Use this when you’re running in the browser, and want to perform the user authorization flow to post back to your server with the access token.

Parameters

clientId: string

Your Spotify client ID

redirectUri: string

The URI to redirect to after the user has authorized your app

scopes: string[]

The scopes to request

postbackUrl: string

The URL to post the access token to

config?: SdkOptions

Optional configuration

Returns

Promise<AuthenticationResponse>

Source

SpotifyApi.ts:254

performUserAuthorization(clientId, redirectUri, scopes, onAuthorization, config)

static performUserAuthorization(clientId, redirectUri, scopes, onAuthorization, config?): Promise<AuthenticationResponse>

Use this when you’re running in the browser, and want to perform the user authorization flow to post back to your server with the access token. This overload is provided for you to perform the postback yourself, if you want to do something other than a simple HTTP POST to a URL - for example, if you want to use a WebSocket, or provide custom authentication.

Parameters

clientId: string

Your Spotify client ID

redirectUri: string

The URI to redirect to after the user has authorized your app

scopes: string[]

The scopes to request

onAuthorization

A function to call with the access token where YOU perform the server-side postback

config?: SdkOptions

Optional configuration

Returns

Promise<AuthenticationResponse>

Source

SpotifyApi.ts:271


withAccessToken()

static withAccessToken(clientId, token, config?): SpotifyApi

Use this when you’re running in a Node environment, and accepting the access token from a client-side performUserAuthorization call. You can also use this method if you already have an access token and don’t want to use the built-in authentication strategies.

Parameters

clientId: string

token: AccessToken

config?: SdkOptions

Returns

SpotifyApi

Source

SpotifyApi.ts:237


withClientCredentials()

withClientCredentials(clientId, clientSecret, config)

static withClientCredentials(clientId, clientSecret, config?): SpotifyApi

Parameters

clientId: string

clientSecret: string

config?: SdkOptions

Returns

SpotifyApi

Source

SpotifyApi.ts:200

withClientCredentials(clientId, clientSecret, config, scopes)

static withClientCredentials(clientId, clientSecret, config, scopes): SpotifyApi

Parameters

clientId: string

clientSecret: string

config: SdkOptions

scopes: string[]

Returns

SpotifyApi

Source

SpotifyApi.ts:207


withImplicitGrant()

static withImplicitGrant(clientId, redirectUri, scopes, config?): SpotifyApi

Parameters

clientId: string

redirectUri: string

scopes: string[]= []

config?: SdkOptions

Returns

SpotifyApi

Source

SpotifyApi.ts:223


withUserAuthorization()

static withUserAuthorization(clientId, redirectUri, scopes, config?): SpotifyApi

Parameters

clientId: string

redirectUri: string

scopes: string[]= []

config?: SdkOptions

Returns

SpotifyApi

Source

SpotifyApi.ts:186