Can n8n do something like a for each but complete each before moving on?

I pull all the companies we manage from our documentation, then I need to iterate over all 22 companies.

What I’m seeing is the companies get pulled, then it tries to process the next node with each company’s first page of data.

Is there a way to get the list of companies, then have n8n process company 1, complete it’s tasks, then loop to process company 2, etc?

{
“meta”: {
“instanceId”: “e0f81dab2ef3044d67766db66a67ac1e7110b99c19e56672c0eaf888e90abe8e”
},
“nodes”: [
{
“parameters”: {},
“id”: “07648bb1-e3ec-4591-b55e-49346de220ff”,
“name”: “When clicking "Execute Workflow"”,
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
620,
300
]
},
{
“parameters”: {
“url”: “https://kginger.huducloud.com/api/v1/companies”,
“sendQuery”: true,
“queryParameters”: {
“parameters”: [
{
“name”: “archived”,
“value”: “false”
}
]
},
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “accept”,
“value”: “application/json”
},
{
“name”: “x-api-key”,
“value”: “”
}
]
},
“options”: {}
},
“id”: “aa5a9a6e-9a6d-4e48-ac24-72427ce62e9e”,
“name”: “Get Hudu Companies”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.1,
“position”: [
800,
300
]
},
{
“parameters”: {
“fieldToSplitOut”: “companies”,
“options”: {}
},
“id”: “7151340f-ebea-439d-856e-f8d2642a2b27”,
“name”: “Split pages to companies”,
“type”: “n8n-nodes-base.itemLists”,
“typeVersion”: 2.2,
“position”: [
1000,
300
]
},
{
“parameters”: {
“fieldToSplitOut”: “id, name”,
“options”: {}
},
“id”: “5598fb79-436a-4b2a-8eb4-357144ac0b59”,
“name”: “Get ID and Name”,
“type”: “n8n-nodes-base.itemLists”,
“typeVersion”: 2.2,
“position”: [
1200,
300
]
},
{
“parameters”: {
“url”: “=https://kginger.huducloud.com/api/v1/companies/{{ $json.id }}/assets”,
“sendQuery”: true,
“queryParameters”: {
“parameters”: [
{
“name”: “page”,
“value”: “={{ $json.PAGE }}”
}
]
},
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “x-api-key”,
“value”: “”
}
]
},
“options”: {}
},
“id”: “c2c37840-1312-44fb-9b21-3e564c9ba3b2”,
“name”: “HTTP Request”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.1,
“position”: [
1400,
300
]
}
],
“connections”: {
“When clicking "Execute Workflow"”: {
“main”: [
[
{
“node”: “Get Hudu Companies”,
“type”: “main”,
“index”: 0
}
]
]
},
“Get Hudu Companies”: {
“main”: [
[
{
“node”: “Split pages to companies”,
“type”: “main”,
“index”: 0
}
]
]
},
“Split pages to companies”: {
“main”: [
[
{
“node”: “Get ID and Name”,
“type”: “main”,
“index”: 0
}
]
]
},
“Get ID and Name”: {
“main”: [
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
}
}
}

Information on your n8n setup

  • n8n version: 1.05
  • Database (default: SQLite):SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker on DO
  • Operating system: Ubuntu 22.04

Hi @russellkg , yes it is doable. In the future, please use the code icon to paste your workflow, it looks like this: </>

Here is what a loop could look like using your flow:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.