How To - Run a workflow for each item

I’m trying to see if I can reuse the same workflow for a list of items and am not quite sure how to achieve this. In essence, I want a list of items (URLs) and to run the workflow separately once for each of those items .I don’t see any way to iterate through items like this and wanted to ask the people who know.

Many Items → One Workflow

How can this be done easily? Thanks in advance for any helpful input.

Welcome to the community @Mike!

Each node runs normally once per item by default with very few exceptions. So if you provide multiple items it should already work.

Maybe I’m overthinking this, but can you provide an example?

From your response I’m imagining delimitating a set variable (so something like: x.com, y.com) and using that variable for the flow. In practice when I attempt that it ends up only passing the response from the first URL through the workflow and not running separately as I would expect. I’m probably passing the URLs incorrectly though so any help is appreciated :stuck_out_tongue:

Check the example below

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      url: 'https://openlibrary.org/isbn/9780140328721'\n    }\n  },\n    {\n    json: {\n      url: 'https://openlibrary.org/isbn/1982139137'\n    }\n  }\n]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        550,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"Function\"].json[\"url\"]}}",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        940,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Okay, I think I got it.

Any good suggestions on building that list dynamically?

Nodes pass along a list of loopable items by default. You can also create your own with the Function node, provided that what you return has the shape Array<{ json: object }>.