Route Data with the Switch Node in n8n

Difficulty
2/10
Tags
EssentialsSwitchHTTP RequestConditional RoutingJSON

Not all data should follow the same path. Sometimes you need to send orders to different departments, route support tickets by priority, or handle users differently based on their subscription level.

The Switch node checks a value and sends items down different output branches based on conditions you define. Think of it like a traffic controller directing cars to different lanes.

In this challenge, you'll route products to different outputs based on their category.

What you'll practice:

  • Using the Switch node to create conditional branches
  • Setting up routing rules based on field values
  • Understanding how items flow through different outputs

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 products from https://dummyjson.com/products?limit=9&skip=3 and route them based on their category:

  1. Products with category "beauty" go to Output 1
  2. Products with category "fragrances" go to Output 2
  3. All other products go to Output 3 (fallback)

The API returns products with different categories. Your Switch node should check the category field and send each product down the correct path.

Example product structure:

{
  "id": 1,
  "title": "Essence Mascara Lash Princess",
  "category": "beauty",
  "price": 9.99
}

Expected result: Products split across 3 outputs based on their category.

Hints

  1. Add a Manual Trigger node to start the workflow
  2. Add an HTTP Request node to fetch from the URL above
  3. The API returns a products array, so add a Split Out node to process each product individually
  4. Add a Switch node after Split Out
  5. In the Switch node, set Mode to "Rules"
  6. Add a rule for "beauty": set Field to category, Operation to "Equals", and Value to beauty
  7. Add a second rule for "fragrances" the same way
  8. Enable the Fallback Output option to catch everything else

Tip: Each rule creates a new output connector on the Switch node. Items matching rule 1 exit from Output 1, rule 2 from Output 2, and non-matching items from the Fallback output.

Explanation

Why we need Switch:

When you have data that needs different handling based on its properties, the Switch node lets you split your workflow into multiple paths. Instead of processing everything the same way, you can route items to specialized branches.

How Rules mode works:

In Rules mode, the Switch node evaluates each item against your rules in order. When an item matches a rule, it exits through that rule's output. If an item does not match any rule and you have enabled the fallback output, it exits through the fallback.

How the solution works:

  1. Manual Trigger: Starts the workflow
  2. HTTP Request: Fetches 9 products from the API (returns 1 item with a products array)
  3. Split Out: Set Field To Split Out to products to convert the array into 9 separate items
  4. Switch: Each rule uses {{ $json.category }} as the value to check, with operation set to "equals" and the category name as the comparison value

Switch node settings: The fallback output is enabled under Options at the bottom of the node settings. You can also rename each output by enabling Rename Output on each rule, which helps identify which branch is which when connecting nodes.

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