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
- Take a list of artists as input
- 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
- 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.
Spotify
- Head to Spotify Developer and register, then create a new app in the My Applications section. Add the
client_id
andclient_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
- Auth URL: https://accounts.spotify.com/authorize
- Access Token URL: https://accounts.spotify.com/api/token
- Client ID: {{client_id}}
- Client Secret: {{client_secret}}
- Scope:
playlist-read-private playlist-modify-private
- Grant Type: Authorization Code
- Request access token locally: Checked
- Click on Request Token, go through the OAuth flow, and add the
refresh_token
to your environment
- Head to Spotify Developer and register, then create a new app in the My Applications section. Add the
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
Collection Config
Set the following variables in your environment
user_id
: your spotify usernamecountry_code
: in ISO 3166-1 formatN
: defaults to 5. Refer to the algorithm section for more detailsartists
: 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
- To verify that everything works as expected, run the collection in the Qodex app using the Collection Runner
- Now you can use Qodex Monitors to schedule the collection run daily or monthly.
-
Get Related Artists GET https://api.spotify.com/v1/artists/{{id}}/related-artists
-
Create a Playlist POST https://api.spotify.com/v1/users/{{user_id}}/playlists
-
Get Artist Top Tracks GET https://api.spotify.com/v1/artists/{{artist_id}}/top-tracks?country={{country_code}}
-
Add Tracks to Playlist POST https://api.spotify.com/v1/users/{{user_id}}/playlists/{{playlist_id}}/tracks?uris={{uris}}
-
Update environment PUT https://api.getpostman.com/environments/{{environment_id}}