Spotify Playlist Generator V2

Number of APIs: 7

Blog series: * Conditional workflows in Qodex * Generate spotify playlists using a Qodex collection * Daily mix with Qodex monitors and spotify

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. Qodex Cloud API
    • Generate a Cloud API key here
    • Store this value under Qodex_api_key
    • (Optional) For a smarter generation, we'll want to the environment to update as well. Get the newly created environment id using the Cloud API as outlined here. In your environment, set the environment_id value to the uid obtained above
  3. 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 and Schedule the Collection

  1. To verify that everything works as expected, run the collection in the Qodex app using the Collection Runner
  2. Now you can use Qodex Monitors to schedule the collection run daily or monthly.

  1. Get Auth Key POST https://accounts.spotify.com/api/token

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

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

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

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

  6. Update environment PUT https://api.getpostman.com/environments/{{environment_id}}

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