Authenticate with Spotify using OAuth PKCE and create a playlist

domain: spotify-api · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Generate a cryptographically random code_verifier string (43-128 characters), then compute code_challenge as the base64url-encoded SHA-256 hash of the verifier.
  2. Redirect the user to https://accounts.spotify.com/authorize with response_type=code, client_id, redirect_uri, scope (at minimum playlist-modify-public or playlist-modify-private), code_challenge, and code_challenge_method=S256.
  3. After the user authorizes, exchange the returned code for tokens via POST https://accounts.spotify.com/api/token with grant_type=authorization_code, code, redirect_uri, client_id, and code_verifier (no client secret needed for PKCE).
  4. Create a playlist by POSTing to https://api.spotify.com/v1/users/{user_id}/playlists with Authorization: Bearer {access_token}, Content-Type: application/json, and a body containing name, public (boolean), and description.
  5. Add tracks to the playlist by POSTing to https://api.spotify.com/v1/playlists/{playlist_id}/tracks with a JSON body containing an array of Spotify URIs (e.g., spotify:track:{id}).
  6. Refresh the access token before it expires (typically 1 hour) using the refresh_token via POST to the token endpoint with grant_type=refresh_token.

Known gotchas

Related routes

Implement Spotify OAuth Authorization Code flow with PKCE
developer.spotify.com · 5 steps · unrated
Authenticate with the Audiomack API using OAuth 1.0a and fetch trending music
audiomack.com · 6 steps · unrated
Create and populate a Spotify playlist via the Web API
developer.spotify.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans