I must be overcomplicating loops. I am creating loops and looking for a simple way to increment. Like to add to the offset value in HTTP calls. I am trying to use the equivalent of the classic “i” value in a JS for loop. Even the examples that AI comes up with are massively unintuitve - replicating set values within loops, using merge nodes. There must be something I am missing. Can someone please point me to the best resources for this?
Hey @rgreen hope all is good
Could you expand on what is it you are trying to achieve? Not how (by implementing a loop) but what? Maybe there is a whole other way to do that.
Hi @jabbson thanks for replying.
I am trying to increment a value for offset across multiple HTTP calls. The API has a 200 results max. I have it working with a merge node, but it makes things more difficult to follow when I show this to my less tech oriented teammates. I could simply do something like i * limit;
in a JS function. Is there a value for the loop iteration in n8n?
Again, this is not “what” you are doing, this is “how” you are doing it. Why do you need to increment an id? I am assuming this may have something to do with pagination?
I am doing this by using a set node where offset is 0. Then I have an HTTP node where the call is made. I then have a merge node that carries the result of the HTTP call and the set node. I then have another set node that increments the offset, and then connects back to the HTTP call. This works, but it seems like it could be simpler.
Ok, so again, you are doing pagination, right? You want each next call to have a value in the query string or the body which increments on each call?
Yes, the offset value in each call is incremented by 200 in each call.
There is a functionality for this in the HTTP Request node, under options.
See here and here to know more.
Thanks for the quick solution! Much appreciated.