Search code examples
spotify

How to get a song recommendations for a playlist on Spotify APi


I am trying to get Spotify song recommendations through the Spotify API (basically, the list of recommended songs for a given playlist on the Spotify app). There is a get recommendations endpoint, but not with a playlist as a parameter: https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations/.


Solution

  • The recommendations endpoint can only be built off of songs, artists, or genres - not playlists. You can pass the data through as seed_tracks, seed_genres, or seed_artists. However, as a note, there can only be up to 5 seed values passed into the recommendations input (5 total, not 5 of each).

    If you wanted to, you could try looping through your playlist in chunks of 5 and sending the track Spotify IDs to the recommendations endpoint, retrieving the result, and append the result to some array. This may be a bit "hacky" as the "recommendations" will only be based on the 5 songs passed through, not the whole playlist. Also, there may be a limit on Spotify's end.