I’ve started experimenting with n8n but I’m stuck at one point. I hope you can give me some tips.
My goal:
I want to mirror my Spotify playlists on YouTube, i.e., synchronize them. Any changes to my Spotify playlists should also be reflected on my YouTube playlists. There are examples at Discover 800+ Automation Workflows from the n8n's Community, but I would like to implement it in my own way.
Currently, my workflow reads my Spotify playlists and uses the “create youtube playlist” node to create any missing playlists. These are initially empty—only the name of the Spotify playlist is created on YouTube. In parallel, I use the “Loop Over Items” node to iterate through each Spotify playlist to read out the individual songs.
My problem:
The marking labeled “A” or “In A only” only returns a value if a new playlist has been created in Spotify. If no new playlist exists, there is no value returned, and “create youtube playlist” is not triggered. Next, I want to prevent the “loop over items” node (labeled “B”) from immediately executing every single time.
I want to achieve the following:
The “loop over items” node should not start if a new YouTube playlist needs to be created. In other words, if “A” returns a value, then “B” should wait until the “create youtube playlist” node finishes.
If “A” does not return a value, meaning no new playlist is needed on YouTube, then “B” can start immediately.
I’m unable to accomplish this with the existing nodes. I can’t use the IF node because IF requires an input value, and “A” doesn’t always produce one—only when new Spotify playlists are created.
Connect an “If/Switch” node to A. If A returns no value, connect to a “No Operation, do nothing” node. If A returns a value, connect to “Create playlist”.
Or change your switch node and add another value and connect that value to the “No Operation” node.
Currently, a new playlist (B) “create youtube playlist” is generated if “In A only” is greater than 0.
How can I delay the execution of (C) “Loop Over Items” until (B) has finished its work?
At the same time, I need (C) to run immediately if (A) is executed, meaning (C) should start right away when no new playlist needs to be created.
Hi Aaron,
I think the merge node is what you are looking for. B and C merged, returning only items of C would be the correct behaviour from what I understand. The merge node will wait for both inputs to arrive before executing.
We’ve created a new category for help with designing workflows, and I’ve moved your question there: Help me Build my Workflow. Find out how this category works by reading this topic.
Well the Merge node returns both A and B right?
So why don’t you do exactly what you described afterwards. Something along the lines of: If B.notEmpty() → true: B, false A ?
(A) always returns a value.
(B) also always returns a value, but most of the time, it’s an empty JSON. Occasionally, (B) contains actual data (playlist).
If (B) returns a value, I need to take the value from (B) and ignore (A).
To determine whether (B) contains a value or not, I use the merge node. (A) must wait for (B).
I still don’t understand how to implement this check using IF statements.
To help you better it would be good to know the data your workflow is processing.
I am assuming that there is one output of B for every output of A.
Instead of appending the objects of A and B in the merge node how about combining them by position? That will leave you with an object containing both outputs A and B (for each run). Then test B for emptyness and proceed like so:
Thank you for thinking of me. I have significantly restructured the workflow and found part of the solution. I have spent a lot of time with n8n over the past few days, and even with support from experienced users on Discord, we couldn’t answer some of my questions. For now, this topic is settled.