Hi all,
I was trying to used loop inside a loop in my workflow but cannot able to iterate it over all the items.
Used Case:
I am fetching my data from google sheets which return data with row multiple. I have to make a get http call for each row individually so for that I am using Split Each Row (SplitIntoBatches) node. Get Http call response contains list of items and for each item I have to make a put http call individually and for that I am using Split Each Item (SplitIntoBatches) node, let say 10 items.
Problem:
For the first row data everything is working fine but once the loop for first row is completed the Split Each Item node run index is set to 10 and noItemLeft is set true. Now for the second row data Split Each item is not able to iterate over its list of items as noItemLeft for that node is set to true due to previous loop execution. Is there a way I reset the value of run index and noItemLeft variables after each loop execution. Or is there any other way to handle this problem.
Hey @harshil1712 ,
Can you help me with this.
Hi @Mustafa_Ali, you wouldn’t usually need to the Split In Batches node if you’re trying to make an API request for individual items as the HTTP Request Node would already run once for each item it receives. So based on your description it sounds like you could simplify your workflow a lot, similar to the example at HTTP request consulting in loop - #3 by MutedJam (where the node runs once for each input item).
Hi @MutedJam . I used the loop for http call to avoid API Rate limit error incase number of items is large.
Ah, so that’s what the wait node is for in your screenshot? You could also cover that without a loop by setting the Batch Interval option on the HTTP Request node and the Batch Size option respectively:
Ah, great. Thats helpful, I guess this will simplify my workflow a lot.
Just curious: How can I use nested loop for any other workflow as mentioned in the question earlier? Is there a way I can reset the value of noItemLeft variable in split node after a loop is completed?
Hey @MutedJam ,
I updated my workflow as you mentioned previously. I am able to make a bulk API call.
Problem: After making the API call I have to update my data in Gsheets. After making an API call I am getting “Cannot read property ‘toString’ of undefined” in Lookup Row in Sheets node. Please let me know how can I resolve it.
My Workflow:
Error in Look Up Row in Sheets:
Output of Post API(Bulk Update)
The error message suggests you might be trying to look up a row using data which is not available (thus the error when n8n tries to use .toString()
). But to be honest, I am not sure I fully understand what exactly you are trying to achieve here.
Do you need to make a series of HTTP calls for every single row you receive from your initial Google Sheet node? That in itself wouldn’t require the Split in Batches node at all as the HTTP Request Node already runs through all items it receives.
Maybe you can simplify your workflow down to the step that’s causing the problem to further investigate what’s happening here? Use a set node to set the data
field you’re trying to use followed by the Google Sheets node performing your lookup. If this still fails, could you share your simplified workflow with us?