Hi everyone, I’m running into an issue with one of my n8n workflows when processing a large response from an API. The workflow pulls data from an external API, processes it in a Function node, and then sends it to my database. It works fine with smaller datasets, but when the API returns a larger response (around a few thousand records), the workflow sometimes stops midway or throws random errors.
The workflow structure is basically:
HTTP Request → Function → Split In Batches → Database
In my Function node, I’m trying to transform the data before passing it to the next node. My code looks something like this:const data = $json.data;
const results = ;
for (let i = 0; i < data.length; i++) {
results.push({
json: {
id: data[i].id,
name: data[i].name,
email: data[i].email,
processed_at: new Date()
}
});
}
return results[0];
Describe the problem/error/question
Sometimes the workflow throws an error saying the output format is wrong, and other times it just processes one item instead of the full list. I’m guessing I might be returning the data incorrectly from the Function node, but I’m not completely sure.
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
It looks like the main issue is in your return statement in the Function node.
You are building an array called results, but at the end you return only one item:return results[0];
In n8n, a Function node that processes multiple items should return an array of items, not a single object. Returning only results[0] means only the first record gets passed to the next node, which explains why sometimes only one item is processed.
You should return the full array instead:const data = $json.data;
const results = ;
for (let i = 0; i < data.length; i++) {
results.push({
json: {
id: data[i].id,
name: data[i].name,
email: data[i].email
}
});
}
return results; // sends all items to the next node
Also, since you are handling large API responses, it’s usually safer to place Split In Batches right after the HTTP Request so the workflow processes the data in smaller chunks instead of loading everything into memory at once.
So the structure would be better like this:
HTTP Request → Split In Batches → Function → Database
This usually makes workflows more stable when dealing with thousands of records.
Hey welcome! Your issue is return results[0] — that only returns the first item. Change it to return results so it passes the full array to the next node. Thats why youre only getting one record through and sometimes getting output format errors. Also if youre hitting memory issues with a few thousand records, set your Split In Batches size to something small like 50
Your n8n workflow is choking on large API responses due to inefficient data processing in the Function node.
I can optimize your workflow to handle bigger datasets using n8n, Supabase, and JSON2Video.
See exactly what I build → myportoliowork.lovable.app — let’s fix this fast.
Agbaje Olarewaju
AI Automation Architect agbajeautomation.me agbaje-assistance.lovable.app