Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Plan: Premium
Country: USA
My Question or Issue
I'm trying to build a view where I can see a list of a user's playlists that a given song appears in. Currently, the only feasible approach given the existing API is to iterate through a user's playlists, then all of their songs in each of those playlists, until I can find the song in that playlist (at which point I can at least stop fetching more songs from that playlist). This is slower and more cumbersome than I'd like.
In light of the official app's new "add to playlist" screen where you can see each of your playlists, and which playlists that track is currently in, this seems particularly inefficient. What are the chance we can get an endpoint that enables similar functionality? Even an endpoint to check if a song exists in a given playlist would be extremely helpful.
I'm also interested to see if anyone's solved this with a better approach that I'm just missing.
Did you figure out any better approach? I am trying to do something similar - get all playlists in which a song appears and in which it does not. Also, I wonder making that many requests could trigger rate limits?
Unfortunately I never found a better way. I really hope this gets added to the public API at some point, cuz this approach makes the UI I'm trying to build almost unusably slow.
The workaround I used is to get all the playlists first, then make concorrent API call for each playlist to fetch all items. My app maitains a local state of every playlist and songs, and I haven't experienced any drastic slowdowns. I was worried if I would be rate limited, but I did not.
I am using the official spotify typescript sdk w/ react by the way.
Keeping it all in state is a good idea (although it kinda feels like a lot of state? I guess if you only fetch the minimal data you need...), I'll have to give that a try. It's been a while since I touched the project, but IIRC I was doing that iterating process as each song came up... Which like, now that you point it out, obviously I should've saved that, I had to go through most of each of a users' playlist every time I did that, might as well at that point. Thanks!
Yeah, iterating approach would be too slow to be useful. Technically, I have six states, but 4 of them are control states, that leaves 2 states: one for list of playlists (array of playlist object), and a tracks, state (array of `{ playlist_id, tracks }`).
I load everything after user logs in, and that state is maintained for all operations until user reloads the page.
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game and get…