Michael Schmitt

Software Developer in Illinois

Discover your favorite artists' new albums using Spotify's API

· 04/07/2019 · spotify ·

In most ways Spotify is great. In some specific ways, Spotify is baffingly bad. One of the most annoying shortcomings of the platform is the inability of Spotify to alert you to new album releases from your favorite artists, even if you've explicitly "followed" the artists in Spotify.

If you're frustrated by this lack of functionality, you can actually pretty easily fill the gap yourself using Spotify's JSON API. This weekend I used the following to build a quick RSS feed for myself that will update itself with new releases from my favorite artists.

To start, you'll need some Spotify API credentials and the tokens necessary to interact with your account. Spotify's documentation walks you through this process.

Once you're set up and can make API requests, set up a call to fetch your user account's list of followed artists. The response will include an "items" payload - the list of artist data - and a "cursors" object with an "after" key you can use to retrieve the next page of artists (note the max limit of artists is 50, so implementing paging is likely required).

Within the payload response for each artist is an "id" value. Use this value to fetch the list of albums by the artist. Note this endpoint requires a "country" param for cleaner results, as well as a "include_groups" param you should customize to releases you're interested in (I used "album" and "single").

The album list response data will include a "release_date" value (which appears to be "YYYY-MM-DD" format, though Spotify's documentation doesn't list this explicitly) to helpfully sort your results.

Note too that both the artist and album response payloads include a "external_urls" key. This is a hash with at least one entry with a key value of "spotify". The value is a Spotify URL that you can rely on to open into the Spotify app on a mobile device, should you want to quickly jump into the app to listen to the new release.

One issue I encountered when setting this up is Spotify's rate limiting is rather aggressive. You'll receive an error response with code 429 if you encounter this problem too. Spotify's documentation directs you to "check the Retry-After header, where you will see a number displayed. This is the number of seconds that you need to wait, before you try your request again."

Those two API calls are just about all you need to generate a list of albums, sorted by release date, from your followed artists on Spotify.

See also: Build Spotify playlists from radio station JSON feeds

Previous Next
Analytics of Delight Salon spotlights Serial Reader
Automate the Boring Stuff with Python