SpotifyApi
Constructors
new SpotifyApi()
new SpotifyApi(
authentication
,config
?):SpotifyApi
Parameters
• authentication: IAuthStrategy
• config?: SdkOptions
Returns
Source
Properties
albums
albums:
default
Source
artists
artists:
default
Source
audiobooks
audiobooks:
default
Source
browse
browse:
default
Source
chapters
chapters:
default
Source
currentUser
currentUser:
default
Source
episodes
episodes:
default
Source
markets
markets:
default
Source
player
player:
default
Source
playlists
playlists:
default
Source
recommendations
recommendations:
default
Source
search
search:
SearchExecutionFunction
Source
shows
shows:
default
Source
tracks
tracks:
default
Source
users
users:
default
Source
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
getAccessToken()
getAccessToken():
Promise
<null
|AccessToken
>
Returns
Promise
<null
| AccessToken
>
the current access token. null implies the SpotifyApi is not yet authenticated.
Source
logOut()
logOut():
Promise
<void
>
Removes the access token if it exists.
Returns
Promise
<void
>
Source
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
switchAuthenticationStrategy()
switchAuthenticationStrategy(
authentication
):void
Parameters
• authentication: IAuthStrategy
Returns
void
Source
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
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
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
Source
withClientCredentials()
withClientCredentials(clientId, clientSecret, config)
static
withClientCredentials(clientId
,clientSecret
,config
?):SpotifyApi
Parameters
• clientId: string
• clientSecret: string
• config?: SdkOptions
Returns
Source
withClientCredentials(clientId, clientSecret, config, scopes)
static
withClientCredentials(clientId
,clientSecret
,config
,scopes
):SpotifyApi
Parameters
• clientId: string
• clientSecret: string
• config: SdkOptions
• scopes: string
[]
Returns
Source
withImplicitGrant()
static
withImplicitGrant(clientId
,redirectUri
,scopes
,config
?):SpotifyApi
Parameters
• clientId: string
• redirectUri: string
• scopes: string
[]= []
• config?: SdkOptions
Returns
Source
withUserAuthorization()
static
withUserAuthorization(clientId
,redirectUri
,scopes
,config
?):SpotifyApi
Parameters
• clientId: string
• redirectUri: string
• scopes: string
[]= []
• config?: SdkOptions