Skip to content

Spotify

BluDood edited this page Dec 29, 2025 · 3 revisions

Setting up environment variables for Spotify

If you would like to enable the /spotify and /ws endpoints, you'll have to do some steps to set them up.

Steps

Getting your sp_dc cookie

This is required to get a "user" token, which is needed for live fetching of player status.

  1. Open https://open.spotify.com and log in if you haven't already
  2. Open DevTools in your browser (usually CTRL+SHIFT+I)
  3. Go to Storage (Firefox), or Application (Chrome/derivatives)
  4. Go to Cookies, https://open.spotify.com, and search up sp_dc
  5. Copy the value

Registering a Spotify application and getting credentials

These credentials are used for fetching the full playback info when an update is received.

You can use SpotiRT to simplify this process. Make sure to enable the Read access to a user's player state scope!

Follow the steps, and copy your client ID, client secret, and refresh token.

Configure the environment variables

Once you've retreived your sp_dc cookie and your application credentials, put them in your .env file like so:

SPOTIFY_DC="your_cookie"
SPOTIFY_CLIENT_ID="your_client_id"
SPOTIFY_CLIENT_SECRET="your_client_secret"
SPOTIFY_REFRESH_TOKEN="your_refresh_token"

Restart the API if it's already running, and the /spotify endpoint should be available! You can also now get live updates by listening to the /ws WebSocket endpoint.

Clone this wiki locally