Getting familiar with REST API(Spotify API) testing using Postman

shah rahman
7 min readApr 10, 2021

Hello, this article is for those who are new to API testing and music lover’s who use Spotify app and wants to get familiar with Postman using Spotify API.

Popularity and use of Postman for API testing quite high for people who don’t have to code and need any IDE to do API testing.

Best way to learn API testing is to play with free API available for developers. One of the free available API with very well maintained documentation is Spotify API.

Anyone who loves music and frequent music listener probably stumble upon to Spotify. For music lover’s, that’s(using Postman) another way to find an artist, add tracks, update playlist, remove tracks from Spotify.

Pre-requisites:

To try out we have to have Postman installed in our device ( we will use MacOS), needs to have an account in Spotify and little bit familiarity with http status code and http methods use for RESTful services

Spotify API Documentation:

Before we start using Postman, lets take a look at API documentation for Spotify

There is a tab Console which lists all the endpoints through an easy-to-use interface.

On the left pan we can see all the available features of Spotify which we use in APP and their associate http methods along with endpoints and it’s usages.

When we click any of the available endpoints i.e Get an Album’s Tracks we can see page which explains how to request to get a response and one important thing to notice is, OAuth required to make a request which means we needs to be logged in to Spotify and needs to generate a OAuth Token for sending request which is at the end of page.When we click “GET TOKEN” it opens a popup where we can select the scope of our token, usually we select all available options.

On the right side pan, we can see how the http request will look like along with curl (client URL) request format.

Postman Quick Review

When we first time launch Postman, there is an option we can start by creating an account or skip it and starts to use the App

When we go to App, we get into this window where we can put our http request to perform certain task, by default it’s selected GET method for http request.

We will try with GET, POST, PUT and DELETE method to get familiar with API requests. Let’s go back to Spotify API documentation to try and play with some endpoints and see their impact on Postman and Spotify App.

Like any webpage, we will start our fun with search feature which allow user to find an artist, track based on search params

We open postman and put the endpoint along with params to find an artist “Bruce Springsteen” and his tracks

We also have to add token in our headers which we already generated as value of Authorization key

After that we just click send request using GET method , in response we get status code 200 and all the available tracks of artist “Bruce Springsteen” in JSON format

When we are searching for artist, we actually used our first http method GET

When we scrolling down the response, can see every track have one specific identifier nameduriwhich is unique for every track and help user to add track in playlist

As we just mentioned playlist, lets create a playlist from Postman, to create a playlist we have to use http method POST

Let’s go back to take a look at Spotify API documentation for how to create a playlist

As we can see, now there is new field to fill,Request Body where we can fill the specifics of our playlist we are about to create.

Another field to fill, is user_id which is actually user name of our Spotify test account can found under profile and as usual we also needs to generate OAuth Token as well which we are already familiar with.

Now in Postman, all are pretty same as GET request we did, here we need to switch our method from GET to POST. End point would be different and in end point we have to replace user_id with our test account user name/id which we can find from our profile page.

New thing we will add here is “Request Body” which will be done under Body and select raw to paste our own playlist name, description and public options.

Make sure to have fresh token every time try out with requests as token also gets expire and will give user status code 401 which means user is not authorized anymore to perform the request

When we click send then new playlist created and in response user gets status code 201

And when we go back to out Spotify App we can see our newly created playlist listed on top

Great, now we have our newly created playlist in Spotify and we also gets familiar with another http method POST

Now we have a playlist, it’s time to add tracks to playlist.Now we have seen “urifor tracks when we checked our search request response, like tracks - playlists are also unique and they also do have uri” .When we try to add tracks in our newly created playlist, so we needs uriof our playlist and track we wish to add our playlist. When we created our playlist, in response we can see it’suri”.

We can add tracks in our playlist as documentation says with POST method as well

Replace playlist id and track id to add along with Authorization Token- click send and we can see our track has been added with status code 201

Let’s go back to Spotify to check and we can see our track has been added

Let’s add few more tracks in the playlist and our playlist looked like this

How about change the order of the tracks in the playlist, let’s take a look in the API documentation and give a try with next http method PUT which will help us to update the playlist

Then try with track reorder with request body and we got status code 200

Let’s take a look at our playlist in Spotify

We can see previous 4th track now moved as 2nd track in the playlist and playlist tracks got reordered.

That’s really nice to move track using http method PUT

Maybe after reorder, we want to remove a track from the playlist. For removing a track, we need to use http method DELETE

And again, let’s take a look at the API documentation, how it can be done

Let’s remove 1st track and 3rd track from the list. Our request went fine and returns status code 200

Let’s take a look at our Spotify App, how it went

As we can see, two tracks has been removed. With this, we also learn how to use http method DELETE

Thanks for bearing this far, hope you also enjoy how to play with http methods GET,POST,PUT and DELETE. Hope It will encourage you to play with Spotify API to learn how RESTful services requests works. There are plenty of endpoints to play with as well.

Happy Learning!

--

--

shah rahman

Has been in software industry over 5 years, loves testing to help making better software