Fetch and Parse API Data in n8n

Difficulty
1/10
Tags
EssentialsHTTP RequestAPIExpressionsJSON

APIs are like waiters at a restaurant — they take your request (order) to the application (kitchen) and bring back a response (your food).

In this challenge, you'll fetch data from a public API that returns random user profiles and extract specific fields from the response.

What you'll practice:

  • HTTP Request node basics
  • Understanding GET requests and URLs
  • Parsing nested JSON response data
  • Using expressions to transform data

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 a random user from https://randomuser.me/api/ and extract these fields into a clean output:

  • full_name: First and last name combined (e.g., "John Smith")
  • email: The user's email address
  • country: The user's country
  • age: The user's age (as a number)

Expected output format:

{
  "full_name": "John Smith",
  "email": "john.smith@example.com",
  "country": "United States",
  "age": 34
}

Hints

  1. Use an HTTP Request node with GET method to fetch from https://randomuser.me/api/
  2. Add an Edit Fields (Set) node to extract and transform the data
  3. The API returns data nested inside a results array — access results[0] to get the user
  4. Name fields are at results[0].name.first and results[0].name.last
  5. Country is under location, age is under dob

Constraints:

  • Use HTTP Request node (not Code node) to fetch data
  • Use Edit Fields node to transform output
  • Final output should only contain the four required fields

Explanation

Why this solution works:

The API returns a complex nested structure, but you only need four specific pieces of data. The solution uses two nodes working together: one to fetch the data, and one to extract exactly what you need.

How it solves the problem:

  1. HTTP Request node fetches the raw data. When you point the HTTP Request node at https://randomuser.me/api/, it sends a GET request (the default) and receives a JSON response. n8n automatically parses this JSON into a JavaScript object you can work with.
  2. Understanding the API response structure. The API wraps the user data inside a results array. The response looks like this: a results array containing user objects with nested name, email, location, and dob fields. Even though there is only one user, it is inside an array. That is why we use results[0] to get the first (and only) item.
  3. Edit Fields node extracts and reshapes the data. For each output field, we write an expression that navigates to the right location:
    • $json.results[0].name.first and $json.results[0].name.last combines first and last name with a space between them
    • $json.results[0].email goes directly to the email field
    • $json.results[0].location.country digs into the nested location object
    • $json.results[0].dob.age extracts age from the dob (date of birth) object

Why dot notation matters: Each . in the expression moves one level deeper into the data structure. Think of it like opening nested folders: results contains an array, [0] opens the first item, name opens another object, and first finally gets the value you want.

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: