Spotify – REST – Qlik

I’ve been itching to do this one ever since I upgraded my Spotify account to premium and started using it on an almost daily basis!  What better data set could you hope for than all your favourite music?

When writing blog posts on Qlik and BI in general it’s often handy to have a data set to hand; to connect to, transform and visualise.  This is why sites with APIs are so useful and the rich variety of sites and companies now offering them makes for a playground of possibilities.  The Spotify API is free and available for anyone with a Spotify account (free, premium or family).  I’ll talk you through how I created my app…

First of all here’s the app in full:

Spotify Blog Post

There’s a heck of a lot more I could do in terms of analysis but I wanted to keep it simple for now to allow space to talk about the REST connection.  Maybe later on I’ll develop the app further and bring in more data.

To create your own app you’ll need to make use of Spotify’s API console which, luckily, is very well laid out and easy to navigate.

Spotify API

Select a query type (in the above case, to get a user’s top artists or tracks).  You’ll need to type in either “artists” or “tracks” into the Type box.  The next 3 boxes you can leave as they are.  Next you’ll need to request a token to get one hour’s access to the API.  Click the GET OAUTH TOKEN button and follow the steps to log into your account.  Hit the TRY IT button and you’ll be presented with your results.  The results come in JSON (JavaScript Object Notation) format.  If you’re unfamiliar with JSON there’s no need to worry as you’ll not need to get involved with it if you don’t want to.  However, do make note of the bottom part of the results.  Here you’ll find the “limit” and “next url” which we’ll come back to when we talk about pagination.


Now we need to put these results into Qlik.  I’m using Qlik Sense for this example but QlikView has the same REST tools.  In Qlik’s list of connection type’s you’ll find the REST connector which, when opened, should look like the below:


Populate the URL box with the URL from the “Endpoint” as shown in the Spotify API.  Where the URL contains {type}  you’ll need to substitute the {} for a value, in this case artists or tracks.  Method needs to be GET because we only want to retrieve information from Spotify rather than push it from Qlik.  The key generation strategy should be left as Sequence ID and the authentication schema should be anonymous.


Pagination is optional but let’s discuss it whilst we’re here:


What is pagination?  Well, APIs come with limits to ensure they are not throttled.  One of those limits is the number of results.  You can circumnavigate this, to a degree, via pagination; effectively bringing back pages of sequential records.  The number of results per page is listed in the JSON results – remember I said we’d come back to that “limit and next url?”  In Qlik set the pagination type to Next URL and paste in the next url from the JOSN results.  This informs Qlik of the page limit and path to take in order to find the next set of results.

After this you’ll need to provide the connection with authorisation details.  Under Query headers enter “Authorisation” and then paste in the API CURL command box text that follows the word “authorisation.”  In my case it was always “Bearer…”  Then give your REST connection a name and you’re good to go!

From the data editor view find your new connection in the connections list and hit the “select data” button.  You’ll be brought to a tree view of your data and the first few rows of each table.  With some APIs you have to edit or even create your own primary and foreign keys but with Spotify’s API the data is well defined.  Navigate through the tables yourself and decide which ones you want to include in your model.  If you have lots of tables you may need to rename some fields to avoid creating synthetic keys and circular references.  For example the field “name” is used to describe artists and albums.


Run the script and check the model view to make sure you’re happy with it.  In the application front end you can use whichever visualisations you see fit.  I used the Climber Cards extension because it’s great for making lists with images just like you’d see in any artist/album top 10.  I’ll provide a list of links to extensions I’ve used at the end of the post.

NB:  The only real bits of script editing I did was to RESIDENT load the artist images table again and this time bring in the max image size (width or height) grouped by artist.  This brings a list of images down to one per artist using an INNER KEEP join.  I needed to do this because the Climber Cards extension was displaying every image associated with an artist rather than one per artist

The Spotify API has an extensive list of queries and I’ve only just scratched the surface but hopefully this inspires you to make more use of APIs in future.  There’s even a Star Wars one!

Here are some of the visualisations closer up:

Top ArtistsTop Artists in PLaylist


Extensions used:

Climber Cards:!/project/58495ea563c0d95471fb8e39

Word Cloud:!/project/56728f52d1e497241ae697ff

Vizlib Gauge:

Finally I heartily recommend this Qlik video if you’re new to REST connectors and APIs:



3 thoughts on “Spotify – REST – Qlik

  1. HI Michael,

    Nice work. Been working with the Twitter API via the REST connector, so it is interesting to see the similarity and differences between different APIs. May have to take a look a the Spotify ones soon.

    Thanks for sharing.


  2. Hi Michael

    Excellent guide. Im trying to do it but with a little change. Im using WITH CONNECTION to send the URL and query headers. Im having a problem with the Header.

    URL “”,
    HTTPHEADER “Authorization” “Bearer BQA…4”

    But it fails… i think because of the header. Do you know something about it?

    Best regards


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s