Spotify Playlist Generator

Number of APIs: 6

The Spotify playlist generator collection lets you get your daily/weekly dose of fresh music. Modeled on the AMAZING Spotify Discover Weekly, within 5 minutes you'll be able to set this up, and even tweak it to your heart's content!

Workflow

  1. Take a list of artists as input
  2. Randomly select an artist from this list and usse Spotify's fantastic Get Related Artists and Get an Artist's top tracks APIs to mashup a playlist
  3. Add these related artists back to the original list and persist back to the environment

Setup the Environment

Click on the Run in Qodex button above to import the collection and environment template within your app.

  1. Spotify
    • Head to Spotify Developer and register, then create a new app in the My Applications section. Add the client_id and client_secret to your environment.
    • Under the newly created app config, add the following Redirect URI - https://www.getQodex.com/oauth2/callback
    • We'll use the Authorization Code Flow to obtain the Refresh Token.
    • Open Qodex, under a new request, click on the Authorization tab, select OAuth 2.0 and fill in these values:
    • Token Name: can be anything
    • Click on Request Token, go through the OAuth flow, and add the refresh_token to your environment
  2. Collection Config

    Set the following variables in your environment

    • user_id: your spotify username
    • country_code: in ISO 3166-1 format
    • N: defaults to 5. Refer to the algorithm section for more details
    • artists: List of seed artists for the collection. You can find them as part of the Spotify artist link (Available in the app): e.g. for Oasis, the link looks something like https://open.spotify.com/artist/2DaxqgrOhkeH0fpeiQq2f4, choose the last section. The artists variable is an array of strings, so it'll look something like: [2DaxqgrOhkeH0fpeiQq2f4, 2ooIqOf4X2uz4mMptXCtie]

Run the Collection

  1. To verify that everything works as expected, run the collection in the Qodex app using the Collection Runner
  2. The same collection executes in Newman as well. Just export the Collection and Environment files and execute the following command
newman -c SpotifyPLGen.json.Qodex_collection -e SpotifyPlGen.json.Qodex_environment
  1. Get Auth Key POST https://accounts.spotify.com/api/token

  2. Get Artist GET https://api.spotify.com/v1/artists/{{id}}

  3. Get Related Artists GET https://api.spotify.com/v1/artists/{{id}}/related-artists

  4. Create a Playlist POST https://api.spotify.com/v1/users/{{user_id}}/playlists

  5. Get Artist Top Tracks GET https://api.spotify.com/v1/artists/{{artist_id}}/top-tracks?country={{country_code}}

  6. Add Tracks to Playlist POST https://api.spotify.com/v1/users/{{user_id}}/playlists/{{playlist_id}}/tracks?uris={{uris}}