How to use Split in batches node

I’m trying to understand how split in batches node works, this is a basic example that I’m working on

{
  "name": "",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "cities = [\"Berlin\", \"Barcelona\", \"London\", \"Paris\"]\nreturn cities;"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        480,
        270
      ]
    },
    {
      "parameters": {
        "batchSize": 1
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        630,
        270
      ]
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "https://api.openweathermap.org/data/2.5/weather",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "q",
              "value": "={{$node[\"SplitInBatches\"].data[\"0\"]}}"
            },
            {
              "name": "appid",
              "value": "exampleOfAppIdHere"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        780,
        270
      ],
      "credentials": {
        "httpHeaderAuth": "OpenWeather"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FunctionItem": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {}
}

So I’m tying to fetch 1 by 1 the cities that are return by the function node

Hey, @Juan_Gabriel_Fraire welcome to the community, I think you can do what you want to do without using the split baches node. Check the example below. Just add your apiKey under appid and then execute the workflow.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        340,
        350
      ]
    },
    {
      "parameters": {
        "functionCode": "return [ { json: { city: 'orlando' } }, { json: { city: 'miami' } } ]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        590,
        350
      ]
    },
    {
      "parameters": {
        "url": "http://api.openweathermap.org/data/2.5/weather",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "appid",
              "value": "01051d1267e38c490bcc447d3a18f738"
            },
            {
              "name": "q",
              "value": "= {{$node[\"Function\"].data[\"city\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        890,
        350
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thanks!, But my question was more related to understand the tool better, and from the conclusion maybe improve the documentation about how to do use it. I mean maybe we should point people to use more function nodes instead, that’s also a valid answer.

I see @Juan_Gabriel_Fraire , execute this example and you will catch the execution flow and hopefully how to use the node.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        340,
        340
      ]
    },
    {
      "parameters": {
        "functionCode": "return [ { json: { city: 'orlando' } }, { json: { city: 'miami' } } ]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        590,
        340
      ]
    },
    {
      "parameters": {
        "batchSize": 1
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        840,
        340
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1190,
        70
      ]
    },
    {
      "parameters": {},
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1410,
        330
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thanks!! I will give a try and maybe document it.