Need Help with Loops

Describe the issue/error/question

I thought it would be a nice party feature to be able to share a playlist of all the songs that were played to everyone :slight_smile:
but sadly I don’t quite know how looping works.

The goal is:

  1. create a spotify playlist
  2. loop and add songs that are not yet in the playlist (or add them, if they are not the last song that was added)

Right now the items in the loop will “add up” and when a song is new it will be added multiple times at ones (as often as the items have added up).

What is the error message (if any)?

Please share the workflow

Share the output returned by the last node

Until now, it is a loop without a exit condition.

Information on your n8n setup

  • n8n version:
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm,, desktop app]:

Hi @g5b63u3n, this looks like a loop that would go on forever as it has no exit condition. I’d strongly recommend avoid such a construct.

How about a slightly different approach such as fetching all the songs that have been played in the last n hours? n8n doesn’t let you specify the after/before parameters of the respective API call, but you could use an IF node to do the filtering. So once the party is over run a workflow like this:

This runs once and should add all recently played songs it finds to your playlist:

No loop required and this approach can also be extended easily, for example by sending out the track list via email to folks without Spotify. Or by adding an Item Lists node removing duplicates. You could even consider triggering this via a Google Calendar event going forward, so no need to run it manually either :slight_smile: