Reference Data from Previous Nodes in n8n

Difficulty
2/10
Tags
EssentialsHTTP RequestEdit Fields (Set)ExpressionsAPIJSON

In n8n, data flows from one node to the next. But sometimes the node directly before you doesn't have all the data you need. It might be two or three steps back in the workflow.

This is called "backwards referencing" and it's essential when you're combining data from multiple sources. Instead of passing every field through every node, you can reach back and grab exactly what you need from any previous step.

In this challenge, you'll work with a workflow that fetches Star Wars characters and their home planets from two separate API calls. Your task is to combine data from both sources into a single output.

What you'll practice:

  • Accessing data from nodes that aren't directly connected
  • Using the INPUT panel to browse previous node outputs
  • Combining data from multiple API calls into one result

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

A workflow is provided that fetches Star Wars character data and their home planets using two separate API calls:

  1. Fetch People calls https://swapi.info/api/people/ and returns character info
  2. Fetch Homeworlds calls each character's homeworld URL and returns planet info

The Create Sentences node is empty. Configure it to output a sentence that combines data from both previous nodes:

Expected output:

{
  "Sentence": "The homeworld of Luke Skywalker is Tatooine. It has desert terrain and arid climate"
}

The challenge: After the Fetch Homeworlds node runs, you only see planet data. The character name seems "lost", but it's not! You need to reference it from the earlier node.

Hints

  1. First, run the workflow once to see what data each node produces
  2. Open the Create Sentences node and add a new String field called Sentence
  3. Look at the INPUT panel on the left side of the Edit Fields window
  4. Click the dropdown at the top of the INPUT panel. This lets you browse ALL previous nodes
  5. Select Fetch Homeworlds to see planet fields: name, terrain, climate
  6. Select Fetch People to see character fields: name, birth_year, homeworld
  7. Drag fields from the INPUT panel into your expression, or type them manually

The key expression syntax:

  • $json.name → data from the current node (planet name)
  • $('Fetch People').item.json.name → data from an earlier node (character name)

Tip: You can build the sentence by combining text and expressions, like: The homeworld of {{ $('Fetch People').item.json.name }} is {{ $json.name }}

Explanation

Why backwards referencing matters:

Real workflows often need to combine data from multiple steps. In this example, we fetch character data first, then use each character's homeworld URL to fetch planet details. After the second API call, we only see planet data, but we still need the character name to build our sentence.

Without backwards referencing, you'd have to manually pass every field through every node. That's tedious and clutters your workflow with unnecessary data.

How it works in n8n:

When you reference a previous node, n8n creates an expression like:

{{ $('Fetch People').item.json.name }}

Breaking this down:

  • $('Fetch People') → look at the output of this specific node
  • .item → get the current item (n8n processes items one at a time)
  • .json.name → access the name field from that item's data

The solution step by step:

  1. Fetch People calls the Star Wars API and returns characters with their homeworld URLs
  2. Fetch Homeworlds uses each homeworld URL to fetch planet details. Now we only see planet data
  3. Create Sentences combines both sources:
    • Planet name, terrain, climate from the current node ($json)
    • Character name from the earlier node ($('Fetch People').item.json)

Real-world example: Imagine fetching customer data from your CRM, then calling a shipping API with their address. To create an order confirmation, you need the customer name (from step 1) and the tracking number (from step 2). Same pattern: different sources, combined at the end.

Copy the Solution

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

Login to see the exercise

Create an account to access challenges and track your progress.

Log in to see exercise

Related Content

Continue your learning journey with these related challenges and guides: