Overview
This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 3. Deep Dive Concepts.
Watch the video above for the full tutorial, or read the written guide below.
What is n8n item linking and why does it matter?
Item linking (also called data linking) is n8n's mechanism for tracking which output items originated from which input items as data flows through a workflow. n8n maintains this chain automatically in most scenarios: a single input always links to its output, and multiple outputs all link back to a single input. When that chain breaks, downstream nodes lose access to ancestor data and throw "paired item data unavailable" errors that stall the workflow.
How to fix broken item linking in n8n Code nodes and Merge nodes
Item linking breaks inside a Code node when the number of output items differs from the number of input items, or when the node constructs entirely new item objects. For example, filtering 10 snack items down to 3 and producing a new product_review field for each means n8n can no longer automatically trace which output came from which input. The fix is to add a pairedItem property to each output object and set its value to the index of the corresponding input item, for instance pairedItem: i where i is the loop counter. n8n reads that field to re-establish the chain, converting red expression previews to green in all downstream nodes.
The Merge node introduces a different failure mode. Its "combine by position" mode pairs items strictly by their order in each branch. If two branches produce items in different sequences, positional merging silently joins the wrong records. A snacks branch ordered by ID and a reviews branch in a different order will cross-link cheese-ball reviews to nacho-chips data. The correct fix is to switch the Merge node to "on matching fields" mode and name the field that uniquely identifies records on both sides.
When the matching field carries different names in each input branch, for example product on one side and product_name on the other, enable the "fields to match have different names" setting and map each side explicitly. After this change, the Merge node joins cheese balls to cheese balls and nacho chips to nacho chips regardless of the order items arrive in either branch.
Key Takeaways
- Item linking is n8n's provenance chain: each output item references the input item it came from, which is what lets a node read fields from nodes several steps earlier in the workflow.
- n8n breaks automatic linking in a Code node when output count differs from input count or when the code constructs brand-new item objects without
pairedItemhints. - Fix broken Code node linking by adding
pairedItem: <input_index>to every output object; n8n uses that field to reconnect the chain and resolve downstream expressions. - Merge node "combine by position" corrupts data silently when the two input branches deliver items in different orders; use "on matching fields" and specify a shared identifier instead.
- The "paired item data unavailable" error and red expression previews in downstream nodes are the diagnostic signals that item linking broke upstream, most often inside a Code node, Merge node, or Split node.
Related Lessons
- Lesson 11: How Branching works in n8n Workflows | Smart Automations with Multiple Paths
- Lesson 12: How to Use Merge Node in n8n | Combine Data Like a Pro
- Lesson 13: How to Use Set Node in n8n | Edit Fields Node | Add, Edit, Clean Data
- Lesson 14: How to Use Aggregate Node in n8n | Combine & Summarize Data
- Lesson 15: How to Use Remove Duplicates Node in n8n | Clean Your Data Fast
Next Steps
Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.