Combine Data from Multiple Sources in n8n

Difficulty
3/10
Tags
EssentialsMergeHTTP RequestManual TriggerAPIJSONData Transformation

The Merge node confused me for a long time. Not the concept itself, but when I actually needed it. I kept reaching for it in situations where it was the wrong tool.

Here's what took me a while to figure out: most workflows are linear. Data flows from one node to the next. If you want data from the beginning of your workflow at the end, you don't need a Merge node. You need expressions. Specifically, backwards referencing, which we covered in the Reference Previous Nodes lesson. I built more workflows than I'd like to admit where I split things apart and merged them back together, when all I needed was $('Node Name').item.json.field to grab data from an earlier step.

So when do you actually need Merge? When your workflow has parallel branches that execute independently, and you need all of their results before the next step can happen. Say you're calling three different APIs at the same time and then sending one email with all the data. Without a Merge node, each branch finishes on its own and triggers whatever comes next independently. You'd send three emails instead of one.

The Merge node has six modes for combining data in different ways. This challenge uses Append (the simplest one). The explanation below covers all six.

What you'll practice:

  • Using the Merge node to combine parallel branches
  • Setting Number of Inputs to handle three branches
  • Understanding when to use Merge vs expressions

Your Task

  1. 1Copy the exercise below
  2. 2Paste into your n8n editor (Ctrl+V)
  3. 3Solve it — use hints if you get stuck
  4. 4Check the solution when done

Fetch users, posts, and todos from the JSONPlaceholder API in parallel and combine them into a single list.

  1. Add a Manual Trigger to start the workflow
  2. Add three HTTP Request nodes, all connected directly to the trigger:
    • Fetch Users: https://jsonplaceholder.typicode.com/users?_limit=3
    • Fetch Posts: https://jsonplaceholder.typicode.com/posts?_limit=3
    • Fetch Todos: https://jsonplaceholder.typicode.com/todos?_limit=3
  3. Add a Merge node. In its settings, set Number of Inputs to 3
  4. Connect all three HTTP Request nodes to the Merge node's three inputs
  5. Mode should be Append (the default)

Expected output: 9 items total (3 users + 3 posts + 3 todos), stacked in one list.

User structure:

{
  "id": 1,
  "name": "Leanne Graham",
  "username": "Bret",
  "email": "Sincere@april.biz",
  ...
}

Post structure:

{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere...",
  "body": "quia et suscipit..."
}

Todo structure:

{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}

Get the exercise workflow

Create a free account to copy exercises into your n8n editor.

Hints

  1. Add a Manual Trigger node to start the workflow
  2. Add three HTTP Request nodes. Connect all three to the trigger's output by dragging three separate connections from the trigger
  3. Name them "Fetch Users", "Fetch Posts", and "Fetch Todos" so you can tell them apart
  4. In each HTTP Request, set the URL to the corresponding endpoint above
  5. Add a Merge node from the node panel
  6. In the Merge node settings, find Number of Inputs and change it from 2 to 3. This adds a third input port on the node
  7. Connect Fetch Users to Input 1, Fetch Posts to Input 2, Fetch Todos to Input 3
  8. The default mode is Append, which stacks all items together. Leave it as is
  9. Run the workflow. You should see 9 items in the Merge node's output: 3 users, then 3 posts, then 3 todos

Explanation

The three HTTP Request nodes all connect to the same trigger, so they run in parallel. The Merge node waits for all three to finish before outputting anything. That waiting behavior is the key thing Merge gives you. Without it, each branch would continue independently and any downstream node would fire three separate times.

The six Merge modes:

Append stacks all items from all inputs into one list. 3 + 3 + 3 = 9 items. No matching, no pairing. That's what you just built. Use it when you need everything in one place and don't care about connecting related items. Supports 2-10 inputs.

Combine by Position pairs items by index. Item 0 from Input 1 merges with Item 0 from Input 2, Item 1 with Item 1, and so on. If one input has more items than the other, the extras get dropped. Say Input 1 has names Alice, Bob, Carol and Input 2 has scores 95, 87, 72. The output is three items, each with both a name and a score. Use this when both inputs are in the same order and you want to "zip" them together. This is my most-used mode. Only works with 2 inputs.

Combine by Matching Fields pairs items that share the same value in a field you choose. Say Input 1 has users with a "userId" field, and Input 2 has posts that also have "userId". Items where the userId matches get merged into one. It has five output types: Keep Matches (only items that matched), Keep Everything (matched and unmatched), Enrich Input 1 (keep all of Input 1, add matching data from Input 2 where it exists), Enrich Input 2 (same but reversed), and Keep Non-Matches (only items that didn't find a match). One gotcha: field names with spaces cause problems with matching. Stick to simple field names. Only works with 2 inputs.

All Possible Combinations pairs every item from Input 1 with every item from Input 2. 3 items x 3 items = 9 output items. 5 x 6 = 30. It grows fast. I've accidentally created thousands of items this way when I meant to use a different mode. Unless you need every possible pairing, you probably want something else. Only works with 2 inputs.

Choose Branch waits for all inputs to finish, then outputs data from only one branch you pick (or an empty item). The data isn't modified. Useful when you need to synchronize parallel branches but only care about one branch's result. Supports 2-10 inputs.

SQL Query lets you write SQL against your inputs using AlaSQL. Available if you know SQL. In practice, there's usually a cleaner way to restructure data earlier in the workflow.

When NOT to use Merge:

If your workflow is a straight line and you want data from an earlier node at a later step, don't split and merge. Use expressions: $('Node Name').item.json.fieldName. That's backwards referencing, covered in the Reference Previous Nodes lesson. Merge is for parallel branches, not for moving data forward.

One exception: binary data (files, images, PDFs). Many nodes strip binary data from their output by default. The Edit Fields node, for example, has a "Strip Binary Data" toggle that's on by default. IF and Switch nodes also don't reliably pass binary data through. So if you downloaded a file earlier in your workflow and need it several steps later, you might need a Merge node to bring it back, even in a linear workflow. This is a known n8n quirk, not something you're doing wrong.

Copy the Solution

Paste into n8n with Ctrl+V to compare with your approach.

How was this lesson?

Get the solution workflow

Create a free account to copy solutions into your n8n editor.

Related Content

Continue your learning journey with these related lessons and guides: