Automation

Using the n8n Loop Over Items Node with Split in Batches

Learn how to utilize the n8n Loop Over Items node for batch processing and API rate-limit controls in automation workflows.

4 min read

Learn how to effectively utilize the n8n "Loop Over Items" node for batch processing and implementing rate limits in automation workflows. This guide covers a step-by-step setup of workflows, common mistakes to avoid, and advanced conditional logic use cases.

Understanding the Loop Over Items Node

The n8n "Loop Over Items" node, also referred to as "Split in Batches," is designed for batch processing in workflows. This node is particularly useful in scenarios where:

  • You need to process data in batches to avoid exceeding API rate limits.
  • API or external services restrict the number of items processed at one time.
  • Dynamic control over workflow execution speed is required.

Notably, the Loop Over Items node should only be used for specific circumstances, as many nodes in n8n are inherently iterative and process multiple input items automatically.

prerequisites

  • Familiarity with the n8n workflow editor.
  • Access to an API or service with rate-limiting considerations.
  • A running instance of n8n.

Setting Up a Simple Batch Workflow

Follow this step-by-step guide to design a straightforward batch processing workflow using n8n.

steps

  1. Add a Manual Trigger Node
    Open your n8n editor and drag a Manual Trigger node to the workspace. This serves as the starting point of your workflow for testing purposes.

    bash
    # Start workflow using a manual trigger in the editor.
  2. Prepare Input Data
    Use nodes like Google Sheets, Spreadsheet, or Set to initialize an array of data for processing.

  3. Insert a Split In Batches Node
    Add the Split In Batches node. This node takes the input array and splits it into smaller portions based on your specified batch size.

  4. Specify the Batch Size
    Adjust the Batch Size property depending on the API or processing requirement. For example, if your API allows 10 requests per second, set the batch size to 10.

  5. Add Optional Wait Node (if Needed)
    A Wait node can help handle rate limits by delaying execution between batches. For instance, set it to wait for 2 seconds before processing the next batch.

    bash
    # Example Wait configuration:
    # Set duration to 2 seconds.
  6. Process the Batches Using Loop Over Items
    Attach a Loop Over Items node to process each item in the batch individually. Configure it accordingly to handle the items.

  7. End the Workflow
    Use any output-related nodes once all items have been processed, such as updating a database or appending rows to a Google Sheet.

  8. Execute the Workflow
    Execute the workflow to verify its behavior. Check that the items are processed correctly in manageable batches.

Common Mistakes and Their Prevention

Adding Conditional Logic in Batch Processing

Use If nodes to selectively process data within a Loop Over Items node. Here’s how to do this:

steps

  1. Add an If Node
    Insert an If node after splitting the items to add a conditional check. For example, check if an item qualifies as "active."

    json
    {
      "operation": "boolean",
      "field": "status",
      "value": "active"
    }
  2. Split Conditional Paths
    Connect the outputs of the If node to different paths. For example, send "true" items to one process and "false" items to another.

  3. Merge Conditional Outputs
    Re-unite all branches into a Merge node to maintain consistency in the number of input and output items.

  4. Check Item Fields Post-Merge
    Ensure merged data re-aligns each input field correctly by matching key-value pairs.

  5. Add a Wait Node and Loop Over Items
    Attach the Loop Over Items node after the merge and include a Wait node if rate limits require time intervals.

Verification and Optimization Tips

FAQ

How do you handle conditional splits in an n8n loop over items?

After splitting data with an If node, ensure outputs are merged back together to maintain consistency. This prevents item mismatches and preserves workflow stability.

Why use a Wait node in n8n loops?

Wait nodes help you manage API rate limits, ensuring requests are sent at acceptable intervals to avoid errors or throttling.

What happens if my batch size doesn’t divide the input items evenly?

The last batch will process fewer items if the total input is not a multiple of the batch size. This is expected behavior and does not impact the workflow execution.


Official reference: n8n documentation.