The n8n If Node is a fundamental building block for creating intelligent and dynamic automation workflows, allowing data to be routed down different paths based on specific criteria. Think of it as a decision-maker; it evaluates incoming data against conditions you define, sending items down a ‘true’ path if they match, and a ‘false’ path if they don’t. Mastering the If Node is crucial for moving beyond simple linear automations and building workflows that can adapt to varying inputs and real-world complexities, handling tasks like filtering leads, processing orders differently based on value, or routing support tickets based on keywords.
What Exactly Is the n8n If Node?
At its core, the If Node is like a fork in the road for your data within an n8n workflow. It receives data items (like rows from a spreadsheet or details from a submitted form) and asks a question about each item based on the conditions you set up. Does this customer’s order total exceed $100? Is this email subject line “Urgent”? Based on the answer (yes or no, true or false), the node directs that specific data item down one of two output paths:
- True Output: Data that meets the condition(s) flows out here.
- False Output: Data that does not meet the condition(s) flows out here.
This simple true/false split is surprisingly powerful. It lets you create tailored processes for different situations without needing separate workflows for every possible scenario. It’s the key to making your automations responsive and, frankly, much smarter.
Setting Up Your First If Condition
Getting started with the If Node is pretty straightforward. Once you add it to your canvas and connect it to a preceding node, you’ll configure its conditions in the parameters panel.
Imagine you have data coming in, perhaps from a webhook when a new customer signs up. You want to check if they signed up through a specific marketing campaign, let’s say ‘SummerSale23’.
- Add Condition: Click the ‘Add condition’ button.
- Select Data Type: Choose the type of data you’re checking in the first dropdown. If the campaign name is text, you’ll select ‘String’.
- Choose Operator: Select the comparison you want to make. To check if the campaign name is exactly ‘SummerSale23’, you’d choose ‘is equal to’.
- Enter Value 1 (The Data to Check): This is where you tell the If Node what data field to look at. You’ll likely use an expression here, picking the relevant field from the input data. It might look something like
{{ $json.body.campaign_source }}
. You can easily pick this using the expression editor’s variable selector. - Enter Value 2 (The Value to Compare Against): Here, you enter the value you’re checking for. In our example, you’d type
SummerSale23
.
And that’s it! Now, any incoming data item where the campaign_source
field is exactly “SummerSale23” will go out the ‘true’ path. All others go out the ‘false’ path.
Choosing the Right Data Type and Operator
The real flexibility comes from the different data types and operators available. Why does the data type matter? Well, comparing numbers (like is greater than
) is different from comparing text (like contains
) or checking if something simply exists (exists
).
Here’s a quick rundown of common scenarios:
- String: Perfect for text. Use operators like
contains
,starts with
,ends with
,is equal to
,matches regex
(for complex pattern matching), or simplyis empty
. - Number: For numerical comparisons.
is equal to
,is greater than
,is less than
,is greater than or equal to
, etc. - Date & Time: Compare dates and times.
is after
,is before
,is equal to
. Super useful for checking deadlines or timeframes. - Boolean: Simple true/false checks.
is true
,is false
. - Array: Check properties of lists.
contains
(does the list include a specific value?),is empty
,length greater than
, etc. - Object: Mainly used to check if an object
exists
oris empty
.
Choosing the correct data type ensures your comparison works as expected. Trying to use “greater than” on text usually doesn’t make much sense!
Handling Multiple Conditions: AND vs. OR
But what if you need more complex rules? The If Node lets you add multiple conditions and combine them. Between conditions, you’ll see a dropdown where you can select either AND or OR.
- AND: All conditions must be true for the data to go down the ‘true’ path. For example:
Order Total > 100
ANDCustomer Status == 'VIP'
. - OR: Any of the conditions can be true for the data to go down the ‘true’ path. For example:
Subject contains 'Urgent'
ORPriority == 'High'
.
You can chain several conditions together using a mix of ANDs and ORs (though keep it readable!) to build sophisticated logic.
Real-World Example: Processing Customer Orders
Let’s solidify this with a practical example. Imagine you run an online store and use n8n to process new orders coming in via a webhook.
- Trigger: Webhook node receives new order data (customer info, items, total amount).
- If Node (High-Value Order Check):
- Condition 1: Data Type:
Number
, Value 1:{{ $json.body.order_total }}
, Operator:is greater than
, Value 2:500
.
- Condition 1: Data Type:
- True Path (Order > $500):
- Connect to a HubSpot node to add a ‘HighValue’ tag to the customer.
- Connect to an Email node to send a personalized thank-you email, maybe mentioning a special perk.
- False Path (Order <= $500):
- Connect to a different Email node to send the standard order confirmation.
- (Optional) Merge Node: After the specific paths, you might have common steps (like adding the order to a Google Sheet). You can use a Merge node to bring both the ‘true’ and ‘false’ paths back together before proceeding to those common steps.
This simple If Node allows you to automatically segment high-value orders for special treatment, enhancing customer experience without manual effort. See how powerful that little fork in the road can be?
Beyond the Basics: Tips and Considerations
As you get comfortable with the If Node, here are a few extra points:
If vs. Switch: When to Use Which?
The If Node is perfect for binary (true/false) decisions. But what if you need to route data based on multiple possible values of a single field? For instance, routing support tickets based on department (‘Sales’, ‘Support’, ‘Billing’). That’s where the Switch Node comes in. It has one input but multiple output paths, each corresponding to a specific value you define. Use If for two outcomes, Switch for many outcomes based on one field’s value.
Don’t Forget the Merge Node!
As seen in the example, if your ‘true’ and ‘false’ branches eventually need to perform the same next action, you’ll often use a Merge Node. This node takes inputs from multiple branches and combines the data items back into a single stream for subsequent nodes. (Just a heads-up: In very old n8n versions prior to 1.0, using a Merge node could sometimes cause both branches of an If node to execute unexpectedly. Modern n8n handles this much more predictably, executing only the path the If node directs data down).
A Quick Note on Conditional Logic Inside Nodes
Sometimes, you need a small conditional check within a single node’s parameter, not a full workflow split. For example, setting an email subject line differently based on input. n8n expressions offer ways to do this using ternary operators ({{ condition ? value_if_true : value_if_false }}
) or the built-in $if()
function ({{ $if(condition, value_if_true, value_if_false )}}
). These are handy for simple inline logic, but for splitting the flow of data items, the If Node is your go-to tool.
Wrapping Up
The If Node is a cornerstone of effective n8n automation. It transforms your workflows from simple data pipelines into dynamic processes that can react and adapt. By understanding how to set up conditions, combine them with AND/OR logic, and choose the right data types and operators, you unlock a new level of automation capability. So go ahead, experiment with it, and start making your workflows smarter today!