Looping Over not working

Describe the problem/error/question: Loop node not working as expected

What is the error message (if any)?: loop runs only once, it does not loop at all.

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.)
{
  "nodes": [
    {
      "parameters": {
        "jsCode": "function extractAllLocs(data) {\n    const locs = [];\n    \n    // Data is an array of objects, each with a urlset\n    data.forEach(item => {\n        if (item.urlset && item.urlset.url) {\n            const urls = item.urlset.url;\n            \n            // Handle both single object and array cases\n            if (Array.isArray(urls)) {\n                // If it's an array, extract loc from each item\n                urls.forEach(urlObj => {\n                    if (urlObj.loc) {\n                        locs.push(urlObj.loc);\n                    }\n                });\n            } else {\n                // If it's a single object, extract the loc\n                if (urls.loc) {\n                    locs.push(urls.loc);\n                }\n            }\n        }\n    });\n    \n    return locs;\n}\n\n// Access the full array from input\nconst data = $input.all().map(item => item.json);\nconst urls = extractAllLocs(data);\n\nconsole.log('Total URLs extracted:', urls.length);\n\n// Return in n8n format\nreturn urls.map(url => ({ json: { url } }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        80,
        120
      ],
      "id": "e347f914-5649-4a1a-ab8f-f633d86c6c52",
      "name": "Code1"
    },
    {
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        300,
        120
      ],
      "id": "db58b54b-916d-4d37-bbf9-f240faf3d31f",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        560,
        200
      ],
      "id": "f2cd01d3-37b9-47bc-8163-2243e0f01f9a",
      "name": "HTTP Request6"
    }
  ],
  "connections": {
    "Code1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "HTTP Request6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request6": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Code1": [
      {
        "url": "https://www.parthiban.info/blog"
      },
      {
        "url": "https://www.parthiban.info/post/the-crucial-sales-competency-your-team-needs-for-sustainable-growth"
      },
      {
        "url": "https://www.parthiban.info/post/management-by-whatsapp"
      },
      {
        "url": "https://www.parthiban.info/post/future-trends-of-revenue-operations-in-india"
      },
      {
        "url": "https://www.parthiban.info/post/unraveling-the-impact-how-revenue-operations-transformed-sme"
      },
      {
        "url": "https://www.parthiban.info/post/4d-method-to-change-any-behaviour"
      },
      {
        "url": "https://www.parthiban.info/post/who-s-running-gtm"
      },
      {
        "url": "https://www.parthiban.info/post/62-of-companies-increased-revenues-as-a-result-of-being-ethical"
      },
      {
        "url": "https://www.parthiban.info/post/focussing-on-employees-contributed-to-42-increase-in-revenue"
      },
      {
        "url": "https://www.parthiban.info/post/revolutionizing-recruitment-the-impact-of-ai-on-hiring-processes"
      },
      {
        "url": "https://www.parthiban.info/post/using-asmr-techniques-for-effective-learning-interventions"
      },
      {
        "url": "https://www.parthiban.info/post/revops-solutions-india-unlocking-revenue-potential"
      },
      {
        "url": "https://www.parthiban.info/post/are-you-complexifying-your-communication"
      },
      {
        "url": "https://www.parthiban.info/post/3-ways-to-learn-faster-transform"
      },
      {
        "url": "https://www.parthiban.info/post/case-study-revenue-operations-at-mission-cloud"
      },
      {
        "url": "https://www.parthiban.info/post/simulating-learning-is-the-best-andragogy"
      },
      {
        "url": "https://www.parthiban.info/post/top-6-reasons-why-sales-fail-in-any-small-and-meduim-enterprises"
      },
      {
        "url": "https://www.parthiban.info/post/the-four-milestones-of-organization-structure-design"
      },
      {
        "url": "https://www.parthiban.info/post/career-strategy-for-millennials"
      },
      {
        "url": "https://www.parthiban.info/post/case-study-enhancing-meeting-setup-efficiency-among-sales-development-re"
      },
      {
        "url": "https://www.parthiban.info/post/role-of-chief-of-staff-in-revenue-operations-for-a-small-and-medium-enterprise"
      },
      {
        "url": "https://www.parthiban.info/post/from-tofu-to-bofu-the-journey-of-turning-curious-visitors-into-loyal-customers-revenue-operation"
      },
      {
        "url": "https://www.parthiban.info/post/bridging-the-gap-how-revenue-operations-can-align-sales-and-marketing-for-sme-success"
      },
      {
        "url": "https://www.parthiban.info/post/how-to-develop-a-leadership-pipeline"
      },
      {
        "url": "https://www.parthiban.info/post/how-to-spend-your-first-10-minutes"
      },
      {
        "url": "https://www.parthiban.info/post/predicting-5-years-cash-flow-operating-profit-using-monte-carlo-simulation"
      },
      {
        "url": "https://www.parthiban.info/post/organizaitontransformation-a-skill-based-org"
      },
      {
        "url": "https://www.parthiban.info/post/teambuilding-activity-don-t-take-it-lightly"
      },
      {
        "url": "https://www.parthiban.info/post/case-study-new-pms-using-the-adkar-change-leadership"
      },
      {
        "url": "https://www.parthiban.info/post/gen-y-s-cannot-be-motivated-only-through-compensation"
      },
      {
        "url": "https://www.parthiban.info/post/improving-employee-engagement-a-million-question"
      },
      {
        "url": "https://www.parthiban.info/post/how-to-avoid-startup-failures"
      },
      {
        "url": "https://www.parthiban.info/post/simon-s-seven-strategy-questions-a-guide-to-insightful-implementation"
      },
      {
        "url": "https://www.parthiban.info/post/best-practices-for-tracking-performance-metrics-for-revops-india"
      },
      {
        "url": "https://www.parthiban.info/post/effective-internal-communication-promotes-employee-engagement"
      },
      {
        "url": "https://www.parthiban.info/post/deliver-flawless-execution-at-lowest-cost"
      },
      {
        "url": "https://www.parthiban.info/post/how-to-influence-in-workplace"
      },
      {
        "url": "https://www.parthiban.info/post/how-to-implement-a-strategic-revenue-operations-process-for-optimizing-sales-and-maximizing-profit"
      },
      {
        "url": "https://www.parthiban.info/post/principle-based-thinking"
      },
      {
        "url": "https://www.parthiban.info/post/deliverable-prioritization-matrix"
      },
      {
        "url": "https://www.parthiban.info/post/change-d-x-v-x-f-r"
      },
      {
        "url": "https://www.parthiban.info/post/employee-engagement-strategy"
      },
      {
        "url": "https://www.parthiban.info/post/business-systems-performance-improvement"
      },
      {
        "url": "https://www.parthiban.info/post/core-competencies-of-team-member-beyond-technical-acumen"
      },
      {
        "url": "https://www.parthiban.info/blog"
      },
      {
        "url": "https://www.parthiban.info/dms"
      },
      {
        "url": "https://www.parthiban.info/services-4"
      },
      {
        "url": "https://www.parthiban.info/disc"
      },
      {
        "url": "https://www.parthiban.info/general-4"
      },
      {
        "url": "https://www.parthiban.info/blank-1"
      },
      {
        "url": "https://www.parthiban.info/unskilled-workforce"
      },
      {
        "url": "https://www.parthiban.info"
      },
      {
        "url": "https://www.parthiban.info/general-8-1"
      },
      {
        "url": "https://www.parthiban.info/revopsassessment"
      },
      {
        "url": "https://www.parthiban.info/access-to-finance"
      },
      {
        "url": "https://www.parthiban.info/leadership-research-and-insights"
      },
      {
        "url": "https://www.parthiban.info/scarf"
      },
      {
        "url": "https://www.parthiban.info/s-projects-side-by-side"
      }
    ]
  },
  "meta": {
    "instanceId": "03ba0e63a7f075d6ad4f746b4c7bf30ff9f793cf98ab1307d9303a84e98abc92"
  }
}

## Share the output returned by the last node
<!-- If you need help with data transformations, please also share your expected output. -->

## Information on your n8n setup
- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**

The loop works great on my instance.

However, if this loop hasn’t been simplified for sharing, it can also be done using a simple HTTP node with batching.
Just set the number of parallel http request (items per batch) and the wait time between requests.

Generally, n8n workflows stop when a node doesn’t return any items. This shouldn’t happen with an HTTP node.

You can try turning on the Always Output Data option in the settings to check if a response was received.

Thank you, I found the issue, the issue was the way I was executing the workflow, when I was testing I was right clicking the last node and executed. that way only it runs once, if I run the entire workflow, the the loop works.

1 Like

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