I Got 99 Problems but an API Ain’t One

Maxwell You
maxyou
Published in
5 min readSep 29, 2018

I created Spotify Voice so I could listen to music unbiased, but you probably already knew that if you have been following my previous posts [1][2]. When creating the app for the first time, I wanted to create something that worked and was usable in a short period of time: AKA a Minimum Viable Product (MVP) in startup lingo. Once the MVP is developed, additional features can be added over time.

This week’s post will go over some of the initial design decisions I made because of this MVP mentality and how I have fixed the issues that cropped up because of them

Many of the odd behaviors you may have noticed while using Spotify Voice are artifacts of how I chose to design some of the features when building the MVP. In this blog post, I want to share my thought process behind two features: duplicating the New Music Friday playlist and liking songs. I will highlight the issues these features had and how I improved their behavior.

A to the P to the I. What’s That Spell?

Source

To help us understand how duplicating the New Music Friday playlist and liking songs features work, we first need to briefly learn about an application programming interface (API).

An API is a way to use code someone else has already written even though you don’t know what the code actually looks like: it is an abstraction. APIs consist of functions that allow you to specify inputs and will return to you data related to that input. Think about it like an ATM: you specify the amount of money you want and the ATM processes your request, then spits out the money you asked for. Throughout your time interacting with the ATM, you don’t know exactly what it did to get your money, but that’s okay because you got your money. Similar to an API, you don’t care what the API does to get your data as long as you get it.

Using an API is synonymous with “calling an API” to developers and that will be the way I refer to using APIs moving forward.

Many applications you use today most likely have public APIs that allow you to interact with the application. Spotify’s API allows developers to connect to their streaming platform and request various forms of data such as playlist tracks, currently playing song, or even adding songs to a playlist.

Duplicating New Music Friday

When using Spotify Voice, clicking New Music Friday for the first time creates a special spotify_voice playlist under your account and copies all the New Music Friday tracks here. But what’s really going on under the hood?

Creating a playlist has its own API function that takes the user’s account ID and a name for the playlist. In our case, the function creates a spotify_voice playlist under your account. Copying tracks in a playlist involve two steps. The first is reading the songs in New Music Friday so we can generate a list of tracks to copy. The second is adding these tracks into the spotify_voice playlist. As you might have figured, there are two separate API functions for each of these steps.

In previous New Music Friday playlists, sometimes, there were more than 100 songs. In these instances, Spotify Voice worked incorrectly in that it only added up to 100 songs to the spotify_voice playlist. This happened because the playlist reading API function limits the number of songs read in a single call to 100. I only called the API function once, so of course we could only add 100 songs total. On top of this, the API function to add songs to a playlist is also limited to adding 100 songs per call. To fix this, I had to add checks to see if there were more than 100 songs in New Music Friday and call the API functions again if so. Spotify Voice is now able to correctly duplicate the New Music Friday playlist in its entirety: no more missing songs, woo!

We got all the New Music Friday songs!

(Skipping) Liked Songs

When you skip a song with Spotify Voice, it means you didn’t like it enough to add it to one of your playlists. It gets removed from your spotify_voice playlist as well to keep track of progress. If you were wondering, this is also taken care of with an API call!

So how does this relate to liking songs? Well, when I first designed Spotify Voice, I didn’t have the idea of creating a spotify_voice playlist. The initial app played through the New Music Friday playlist and liked songs would get added to the designated playlist you had selected. Progress through New Music Friday wouldn’t be tracked because I didn’t have a way to do so. Therefore, the like button needed only to add songs to a playlist. If you used the app last week, you may have noticed that liking a song didn’t remove it from the spotify_voice playlist. So, if you continued to listen to the song until it ended, then the spotify_voice playlist would reflect incorrect progress since the song would still be there. I have fixed this now by adding an API call to remove the song when liked, so progress should be updated correctly.

Liking a song removes it from the spotify_voice playlist!

One thing to note: if you listen to a song all the way through without liking or skipping it, then the song will not be removed from the spotify_voice playlist. As of now, I am not planning on addressing this scenario because a decision should be made on the song before it is over. I understand sometimes it can be hard to decide, so I recommend making a playlist to add songs you would like to give a second try later.

APIs Everywhere

You can imagine how API calls are initiated for each action in Spotify Voice. When you skip, like, or play/pause, everything invokes an API call to Spotify which helps it carry out the desired action. Some of the annoyances of Spotify Voice were related to the way I implemented my app when creating the MVP. Improving the ways in which the APIs were called helped to get rid of those annoyances and improve the user experience at the same time.

Song of the Week

Fiction by Kygo ft. Tom Odell [Spotify][YouTube]

--

--