G: Hey there, automation enthusiasts! 👋 Are you ready to take your n8n workflows from linear tasks to intelligent decision-makers? If you’ve been playing around with n8n, you know its power lies in connecting apps and automating repetitive tasks. But what happens when your workflow needs to make a choice? What if you only want to send an email if a certain condition is met, or process data differently based on its content?
That’s where the mighty n8n If node comes into play! 🚦 It’s one of the most fundamental and powerful nodes you’ll use, acting as the “brain” of your workflow by introducing conditional logic. For beginners, understanding the If node is a game-changer, opening up a world of possibilities for more dynamic and responsive automations.
In this comprehensive guide, we’ll demystify the n8n If node. We’ll break down its anatomy, show you exactly how to set it up, and then dive into 10 exciting, real-world scenarios that will transform your understanding and give you immediate practical skills. Let’s dive in! 🚀
1. What is the n8n If Node? 🤔
Imagine your n8n workflow as a road trip. Most nodes are like straight stretches of highway, taking you directly from point A to point B. But what if you encounter a fork in the road? Do you go left or right? The If node is precisely that fork.
At its core, the If node evaluates a condition you define. Based on whether that condition is true
or false
, it directs the flow of your data down one of two paths:
- ➡️ The “True” branch: If the condition is met.
- *️⃣ The “False” branch: If the condition is not met.
Think of it like a simple question: “Is X greater than Y?”
- If “Yes” (True), do this.
- If “No” (False), do that.
This seemingly simple concept is the foundation of complex, intelligent workflows. It allows your automations to adapt to different situations, making them incredibly versatile and powerful! 💪
2. Anatomy of the If Node: A Closer Look 🔬
Before we jump into examples, let’s understand the key components of the If node. When you drag an If node onto your canvas, you’ll see several options in its configuration panel:
2.1. Input Data 📥
The If node needs data to evaluate. This data comes from the preceding nodes in your workflow. You’ll typically reference specific fields within this incoming data using n8n’s expression syntax: {{ $json.yourFieldName }}
.
2.2. Conditions: The Brains of the Operation 🧠
This is where you define the logic. An If node can have one or multiple conditions. Each condition consists of three parts:
- Value 1 (Operand A): This is usually the data point you want to check. For example,
{{ $json.orderTotal }}
or{{ $json.customerStatus }}
. - Operator: This defines the type of comparison. n8n offers a wide range of operators:
Equal
:==
(Is Value 1 exactly the same as Value 2?)Not Equal
:!=
(Is Value 1 different from Value 2?)Greater Than
:>
(Is Value 1 numerically larger than Value 2?)Greater Than or Equal
:>=
Less Than
:<
Less Than or Equal
:5
ANDY == 'Active'
“)
- OR: At least one of the conditions must be true for the If node to output to the “True” branch. (e.g., “If
Z == 'Admin'
ORZ == 'Moderator'
“)
2.4. Output Branches: True & False ➡️*️⃣
Once the If node evaluates its conditions, it will send the incoming data item(s) to either the “True” branch (connected to the left output) or the “False” branch (connected to the right output). You’ll then connect other nodes to these branches to define what happens next.
3. Setting Up Your First If Node (Step-by-Step) 👣
Let’s walk through a simple setup. Imagine you receive customer feedback, and you want to process negative feedback differently.
-
Add Your Initial Node: Start with a node that generates some data, like a
Start
node with some JSON data, or anHTTP Request
node, or aWebhook
node. For this example, let’s use aSet
node to simulate incoming data:- Add a
Set
node. - Under “Values,” add a new field:
- Name:
feedbackScore
- Value:
3
(for testing, we’ll change it later) - Name:
feedbackComment
- Value:
Could be better.
- Name:
- Add a
-
Add an If Node:
- Click the
+
icon after yourSet
node. - Search for “If” and select the If node.
- Click the
-
Configure the If Node:
- In the If node’s settings panel, click “Add Condition.”
- Value 1: Click the
fx
(expression) icon. A modal will pop up. Navigate toCurrent Node > JSON
and selectfeedbackScore
. It should insert{{ $json.feedbackScore }}
. - Operator: Select
Less Than
(<). - Value 2: Type
4
. - This condition now reads: “If
feedbackScore
is less than4
.”
-
Connect Subsequent Nodes:
- Now, click the
+
icon on the left output (the “True” branch) of the If node. Add aSet
node.- Configure it with Name:
sentiment
and Value:Negative
.
- Configure it with Name:
- Click the
+
icon on the right output (the “False” branch) of the If node. Add anotherSet
node.- Configure it with Name:
sentiment
and Value:Positive/Neutral
.
- Configure it with Name:
- Now, click the
-
Test Your Workflow!
- Click “Execute Workflow” in the top right.
- Observe the flow:
- If
feedbackScore
in yourSet
node was3
, the If node will output to the “True” branch, and the “Negative”Set
node will run. - If you change
feedbackScore
to4
or5
in the initialSet
node and re-execute, the If node will output to the “False” branch, and the “Positive/Neutral”Set
node will run.
- If
Congratulations! You've just built your first conditional workflow! 🎉
4. 10 Practical If Node Scenarios for Beginners 🚀
Let's explore some common and incredibly useful scenarios where the If node shines. Each example will show you the problem, the solution with the If node, and the typical setup.
Scenario 1: Email Domain Filtering 📧
- Problem: You receive registrations or inquiries, and you want to distinguish between internal users (e.g.,
@yourcompany.com
) and external users. - Solution: Use the
Ends With
operator to check the email domain. - If Node Setup:
- Value 1:
{{ $json.emailAddress }}
(assuming an email field from a form or CRM) - Operator:
Ends With
- Value 2:
@yourcompany.com
- Value 1:
- What happens next:
- True Branch: Send an internal notification, assign to an internal team.
- False Branch: Add to a general marketing list, send external welcome email.
Scenario 2: Numeric Threshold Alert 📈
- Problem: You're monitoring a metric (e.g., sales, stock level, server load) and need to trigger an alert if it crosses a certain threshold.
- Solution: Use
Greater Than
orLess Than
operators. - If Node Setup:
- Value 1:
{{ $json.currentStock }}
(from an inventory system) - Operator:
Less Than
- Value 2:
50
(your reorder threshold)
- Value 1:
- What happens next:
- True Branch: Send a Slack message to the purchasing department, create a reorder task.
- False Branch: Do nothing, or log “stock levels are healthy.”
Scenario 3: Form Field Validation (Required Fields) ✅
- Problem: You receive form submissions, and you need to ensure essential fields (like “phone number” or “address”) are not empty before proceeding.
- Solution: Use the
Is Not Empty
operator. - If Node Setup:
- Value 1:
{{ $json.phoneNumber }}
(from a form submission) - Operator:
Is Not Empty
- Value 2: (Leave blank for
Is Not Empty
)
- Value 1:
- What happens next:
- True Branch: Process the submission (add to CRM, send confirmation).
- False Branch: Send an error email to the submitter, log a validation error.
Scenario 4: VIP Customer Segmentation 👑
- Problem: You have different tiers of customers (e.g., “Standard,” “Gold,” “Platinum”) and want to offer different services or communications based on their status.
- Solution: Use the
Equal
operator. For multiple tiers, you might chain If nodes or use multiple conditions withOR
for similar tiers. - If Node Setup (for Platinum):
- Value 1:
{{ $json.customerTier }}
(from your CRM or database) - Operator:
Equal
- Value 2:
Platinum
- Value 1:
- What happens next:
- True Branch: Assign to a dedicated support queue, send a personalized offer.
- False Branch: Pass to another If node for “Gold,” then “Standard,” or process as default.
Scenario 5: Order Status Processing 📦
- Problem: After an order is placed, you want to perform different actions based on its current status (e.g., “Pending,” “Shipped,” “Cancelled”).
- Solution: Use the
Equal
operator. - If Node Setup:
- Value 1:
{{ $json.orderStatus }}
(from an e-commerce platform) - Operator:
Equal
- Value 2:
Shipped
- Value 1:
- What happens next:
- True Branch: Send a shipping confirmation email, update inventory.
- False Branch: Check if
Cancelled
(another If node), or just log as “Pending/Other.”
Scenario 6: Subscription Expiry Check 📅
- Problem: You want to notify users whose subscriptions are expiring soon, or flag accounts that are already expired.
- Solution: Compare the expiration date with the current date using date operators.
- If Node Setup:
- Value 1:
{{ $json.subscriptionExpiryDate }}
(ensure this is a date/time object or string n8n can compare) - Operator:
Is Before
(orIs On Or Before Date
) - Value 2:
{{ $now }}
(n8n's expression for the current date/time)
- Value 1:
- What happens next:
- True Branch: Send “Your subscription has expired” email, downgrade account.
- False Branch: Check if
Is Before
{{ $now.plus({ days: 7 }) }}
(expiring in 7 days) to send a reminder.
Scenario 7: Multiple Choice Response Routing 📋
- Problem: You're processing survey responses, and depending on a user's answer to a multiple-choice question, you want to follow different paths.
- Solution: Use
Equal
withOR
conditions for similar answers. - If Node Setup:
- Condition 1:
- Value 1:
{{ $json.surveyAnswer }}
- Operator:
Equal
- Value 2:
Yes
- Value 1:
- Condition 2 (Add another condition, set to OR):
- Value 1:
{{ $json.surveyAnswer }}
- Operator:
Equal
- Value 2:
Maybe
- Value 1:
- Condition 1:
- What happens next:
- True Branch: Add to a “follow-up” list, send more information.
- False Branch: Add to a “no interest” list, do not send further communication.
Scenario 8: API Response Success Check ✔️
- Problem: After making an API request, you need to verify if the request was successful (e.g., HTTP status code 200) before processing the data.
- Solution: Check the
statusCode
field from the HTTP Request node. - If Node Setup:
- Value 1:
{{ $json.statusCode }}
(from the previous HTTP Request node's output) - Operator:
Equal
- Value 2:
200
- Value 1:
- What happens next:
- True Branch: Process the API response data, save to database.
- False Branch: Log an error, send an alert to an admin, retry the request.
Scenario 9: File Size Restriction 📂
- Problem: You receive file uploads (e.g., via a webhook or email attachment) and want to reject or handle differently any files that are too large.
- Solution: Check the
file.size
property of the incoming binary data. - If Node Setup:
- Value 1:
{{ $binary.data.file.size }}
(assuming your previous node outputs binary data named “data” with a “file” property that has a “size” attribute) - Operator:
Greater Than
- Value 2:
5000000
(for 5 MB, as size is in bytes)
- Value 1:
- What happens next:
- True Branch: Send a “File too large” email, delete the file.
- False Branch: Process the file (save to cloud storage, attach to a record).
Scenario 10: User Role-Based Access 🧑💻
- Problem: You have different user roles (e.g., “admin,” “editor,” “viewer”) and want to allow or restrict certain actions based on their role.
- Solution: Use the
Equal
operator to match the user's role. - If Node Setup:
- Value 1:
{{ $json.userRole }}
(from your authentication or user management system) - Operator:
Equal
- Value 2:
admin
- Value 1:
- What happens next:
- True Branch: Proceed with administrative tasks (e.g., update settings, manage users).
- False Branch: Block the action, or pass to another If node to check for “editor” role for different permissions.
Conclusion ✨
The n8n If node is truly a cornerstone of building robust and intelligent automations. By mastering its simple yet powerful conditional logic, you unlock the ability to create workflows that are not just linear, but dynamic, responsive, and tailored to specific data conditions.
Don't be afraid to experiment with different operators, combine multiple conditions, and chain If nodes together to build even more intricate decision trees. The more you practice, the more intuitive it becomes!
So go ahead, open up your n8n canvas, and start implementing some of these scenarios. You'll be amazed at how much more powerful your automations can become with just this one crucial node. Happy automating! 🎉
If you found this guide helpful, share it with your fellow n8n enthusiasts! What are your favorite If node scenarios? Let us know in the comments! 👇