Hey N8N Community!
I’m working on a workflow where I need to process a variable number of ID-Category pairs dynamically, but I’m running into an issue with my current approach. Would love some guidance!
Current Setup
Here’s what my workflow snippet does:
- Input: Receives a Product Title
- Internal API Call: Returns response in this format:
json
[
{
"output": {
"Product_Title": "Xech Ellips Fusion of Time & sound",
"ID1": 25625,
"Category1": "Computer Headsets",
"ID2": 147636,
"Category2": "Gents Urinal"
}
}
]
- Set Node: Creates an array to feed into Split Out1 node
- Split Out1: Separates items to process one by one in the loop
- Loop Over Items: Processes each ID-Category pair
The Problem 
My Internal API can return up to 5 ID-Category pairs, but sometimes returns fewer (1, 2, 3, or 4 pairs).
Currently, my Set node is hardcoded to expect 5 pairs, so when the API returns fewer pairs, it creates null:null
entries for the missing ones. These null pairs get sent into the loop and cause errors downstream.
Example of the issue:
- API returns only 2 pairs (ID1/Category1, ID2/Category2)
- Set node still creates entries for ID3-ID5, resulting in null values
- Loop processes these null entries → Error!
What I Need
I want to handle this dynamically so that:
- Only the actual number of returned ID-Category pairs are processed
- No null/empty pairs are sent into the loop
- The workflow adapts automatically whether I get 1, 2, 3, 4, or 5 pairs
Workflow Snippet
Attempted Solutions
I’ve tried modifying the Set node, but I’m not sure how to make it dynamically detect and process only the existing pairs without hardcoding.
Questions
- What’s the best way to dynamically create an array based on the actual number of ID-Category pairs returned?
- Should I use a different approach than Set → Split for this use case?
- Any JavaScript expressions or functions that could help filter out null/undefined pairs?
Would really appreciate any suggestions or alternative approaches! Thanks in advance!