How to iterate in various items using previous node variables

Describe the issue/error/question

Hi everyone!

I’m asking a question to know the best practices (if any) about iterating various node and items in HTTP request. Let’s start with an example.

I’ll start with a HTTP Request node to make an api call. I will receive a list of items. For each item, i want to call two different apis. The first one will (for example) generate an invoice with the data of the first item read in the previous node. The second one will use two data: the invoice just generated and also the item read in the previous node, so a combination of information between the two.

If i were in php, i would have an array declared first with all my items, then looping through that array, i would call the two APIs in sequence, the first call using the data from the item itself, and generating the invoice. The second API would use both the invoice data and the item data (the one the loop is iterating).

How can i achieve this result in n8n using nodes? I have tried to read about looping, but it seems that if i make a first HTTP Request node and receive my list of items, then add a second HTTP Request node to generate the invoice (for example) it will make that call for every item immediatley, returning a response foreach call made. I would instead like it to iterate like a ‘normal’ loop: first item → first api call → second api call → then go to second item and repeat.

How can i do that? Any suggestion will be appreciated.

Hey @Sengerio,

You could try using the split in batches node if you wanted more control over the looping, So you could take all of your output items from the HTTP Request and process them 1 at a time to generate the invoice then move to the next step and at the end just loop back to the start of the split in batches node and all should be good.