Generate Spotify Playlists using a Postman Collection

This continues from my previous post in the series Conditional Workflows in Postman. We will continue to focus on Postman Collections and elaborate on Postman Runtime.

Today, we are going to create our own on-demand playlist using the Spotify API and Postman Collections.

I love Spotify. Over the years it has helped me discover great music. Discover Weekly, in particular, has made me look forward to Monday mornings, with some amazing curated music delivered to the app. Usually, when I come across a great new artist, I look for their top songs and when a bit more adventurous, check out the related artists and repeat the process. Quickly jotting this down into a workflow:

  1. Choose the artist(s) that you like.
  2. Randomly choose one (let’s say The Who) from the list and GET the meta information using Spotify API
  3. Get artists related to The Who and choose a random 5
  4. Create a playlist named “The Who Mix”
  5. GET the most popular songs from The Who, choose a random 5 and add to the playlist
  6. For each related artist, do the same

And that’s it! We get a brand new playlist.


Click the Run in Postman button below to get the Collection and Environment in your Postman app.

You can find detailed documentation for the collection here.

Setup the Environment:

1. Spotify

a. 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.
b. Under the newly created app config, add the following Redirect URI – “”
c. We’ll use the Authorization Code Flow to obtain the Refresh Token.
d. Open Postman, under a new request, click on the Authorization tab, select OAuth 2.0 and fill in these values:

Click on Request Token, go through the OAuth flow, and add the refresh_token to your environment


2. Environment Config

Set the following variables in your environment
a. user_id: your spotify username
b. country_code: in ISO 3166-1 format
c. N: defaults to 5. Refer to the algorithm section for more details
d. 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, choose the last section. The artists variable needs to be set up as an array of strings, that is, with square brackets and double quotes. So it’ll look something like: [“2DaxqgrOhkeH0fpeiQq2f4”, “2ooIqOf4X2uz4mMptXCtie”]

3. Run the Collection

a. Now run the collection in the Postman app using the Collection Runner

By keeping Persist Variables checked, the next time we run this collection, it will add the newly discovered Related Artists to the original seed and thus expanding the scope of discovery, each time we run this collection.


b. The same collection executes in Newman as well. Just export the Collection and Environment files and execute the following command

In the final post of this series, we will schedule this collection to run every week for that true Discover Weekly experience.

Update: Part 3 of non-linear workflows using Postman

Part 3: “Daily Mix” with Postman Monitors and Spotify

Author: ankit

Founder and CTO | Postman

7 thoughts on “Generate Spotify Playlists using a Postman Collection”

  1. Thank you for your interesting blog post. I tried out your template for creating a Spotify Playlist. Unfortunately, Postman yields an error when I run the tests:

    “Error executing pre-request scripts for Get Artist Top Tracks: SyntaxError: Unexpected token u in JSON at position 0”

    When I try it manually it works. Can you reproduce this error?


    1. hi Yashwant I have same error like comment below (Error executing pre-request scripts for Get Artist Top Tracks etc..) Do you observe the same or how do you work around it? Cheers, Charlie

  2. Great article, but I found no mention of how {{client_credentials}} is defined in “Get Auth Key” request.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.