G: Hey there, automation enthusiasts! 👋 Are you ready to supercharge your n8n workflows and make them truly intelligent? If you’ve ever wanted your automations to make decisions based on specific conditions, then you’re in the right place! Today, we’re diving deep into the n8n If node – the brain of your conditional workflows.
The If node is arguably one of the most powerful and frequently used nodes in n8n. It allows you to create dynamic paths in your workflow, ensuring actions are taken only when certain criteria are met. No more rigid, one-size-fits-all automations! 🚀
In this comprehensive guide, we’ll break down the If node’s core components and then empower you with 10 practical, real-world examples that you can immediately apply to your own n8n projects. Let’s get started!
Understanding the n8n If Node: Your Workflow’s Decision Maker 🧠
At its heart, the n8n If node is all about conditional logic. It takes incoming data, evaluates it against a defined condition, and then outputs that data through one of two branches:
- True Branch (✅): The data goes here if the condition is met.
- False Branch (❌): The data goes here if the condition is NOT met.
Think of it like a fork in the road. The If node decides which path your data takes next. This simple mechanism opens up a world of possibilities for creating sophisticated, adaptive automations.
Key Components of the If Node: What You Need to Know 🛠️
When you add an If node to your workflow, you’ll see several configuration options. Let’s break down the most important ones:
-
Value 1 (First Value):
- This is the primary data point you want to evaluate. It can be a static value (e.g., “admin”, 100) or, more commonly, an expression that dynamically pulls data from previous nodes (e.g.,
{{ $json.userRole }}
,{{ $json.orderTotal }}
,{{ $json.email }}
). - Tip: Use the “Add Expression” button (the gear icon ⚙️) to easily select data from previous nodes.
- This is the primary data point you want to evaluate. It can be a static value (e.g., “admin”, 100) or, more commonly, an expression that dynamically pulls data from previous nodes (e.g.,
-
Operation:
- This defines how
Value 1
should be compared toValue 2
. n8n offers a wide range of operations:- Equality:
Equals
,Not Equals
- Containment:
Contains
,Not Contains
- Numeric Comparison:
Greater Than
,Greater Than or Equal
,Less Than
,Less Than or Equal
- String Matching:
Starts With
,Ends With
,Matches Regex
(for advanced pattern matching) - Emptiness:
Is Empty
,Is Not Empty
- Boolean:
Is True
,Is False
- …and more!
- Equality:
- This defines how
-
Value 2 (Second Value):
- This is the value
Value 1
will be compared against. Like Value 1, it can be a static value or an expression pulling data from another part of your workflow.
- This is the value
-
Data Type:
- Crucial! This tells n8n how to interpret
Value 1
andValue 2
before comparison. Selecting the correct data type is vital for accurate results. - Common types:
- String: For text comparisons (e.g., “hello”, “completed”).
- Number: For numerical comparisons (e.g., 10, 150.75).
- Boolean: For true/false values.
- DateTime: For comparing dates and times.
- Empty: For checking if a value exists or not (often used with
Is Empty
/Is Not Empty
operations).
- Crucial! This tells n8n how to interpret
-
Case Sensitive:
- Available for string operations. If checked, “Admin” is different from “admin”. If unchecked, they are treated the same.
10 Practical Examples: Unleashing the Power of the If Node! 💡
Let’s dive into some real-world scenarios to see the If node in action. For each example, we’ll outline the scenario, the data involved, and how to configure your If node.
Example 1: User Role Check for Admin Access 👩💻
Scenario: You want to send notifications only to users with an “admin” role.
Inputs: An incoming webhook or database query provides user data, including a role
field.
Data Example: {"userName": "John Doe", "role": "admin", "email": "john.doe@example.com"}
If Node Configuration:
- Value 1:
{{ $json.role }}
- Operation:
Equals
- Value 2:
admin
- Data Type:
String
- Case Sensitive: ✅ (If “admin” must be exact case) or ❌ (If “Admin”, “ADMIN” should also match)
Outcome:
- True Branch (✅): Proceed to send admin-specific notifications.
- False Branch (❌): Skip notifications for non-admin users.
Example 2: Order Value Threshold for Discounts 💰
Scenario: Apply a 10% discount only if the total order value exceeds $100.
Inputs: An e-commerce system provides orderTotal
.
Data Example: {"orderId": "ORD123", "orderTotal": 125.50, "customerEmail": "customer@example.com"}
If Node Configuration:
- Value 1:
{{ $json.orderTotal }}
- Operation:
Greater Than
- Value 2:
100
- Data Type:
Number
Outcome:
- True Branch (✅): Apply the 10% discount logic.
- False Branch (❌): Process the order without a discount.
Example 3: Filtering Emails from Specific Domains 📧
Scenario: Route support tickets differently if they come from a @premiumcustomer.com
domain.
Inputs: An email parser or CRM provides emailAddress
.
Data Example: {"ticketId": "TKT456", "subject": "Urgent Issue", "emailAddress": "alice@premiumcustomer.com"}
If Node Configuration:
- Value 1:
{{ $json.emailAddress }}
- Operation:
Ends With
- Value 2:
@premiumcustomer.com
- Data Type:
String
- Case Sensitive: ❌ (Good practice for emails)
Outcome:
- True Branch (✅): Route to premium support queue.
- False Branch (❌): Route to standard support queue.
Example 4: Task Status Not Completed 🚧
Scenario: Send a reminder if a task’s status is anything other than “completed”.
Inputs: A project management tool provides taskStatus
.
Data Example: {"taskId": "TSK789", "taskName": "Review Marketing Plan", "taskStatus": "in progress"}
If Node Configuration:
- Value 1:
{{ $json.taskStatus }}
- Operation:
Not Equals
- Value 2:
completed
- Data Type:
String
- Case Sensitive: ❌
Outcome:
- True Branch (✅): Send a reminder email to the assignee.
- False Branch (❌): Do nothing (task is completed).
Example 5: Checking for Empty Shipping Address 📦
Scenario: If a customer’s shipping address is missing, flag the order for manual review.
Inputs: An order processing system provides shippingAddress
.
Data Example: {"orderId": "ORD789", "customerName": "Jane Doe", "shippingAddress": ""}
(or null
, or the field might be missing)
If Node Configuration:
- Value 1:
{{ $json.shippingAddress }}
- Operation:
Is Empty
- Data Type:
String
(orEmpty
for a more general check)
Outcome:
- True Branch (✅): Add order to a “manual review” list or send internal alert.
- False Branch (❌): Continue with normal shipping process.
Example 6: Newsletter Subscription Status 🔔
Scenario: Add a contact to a specific marketing list only if is_subscribed
is true.
Inputs: A lead capture form or CRM provides is_subscribed
.
Data Example: {"contactId": "CNT001", "email": "info@example.com", "is_subscribed": true}
If Node Configuration:
- Value 1:
{{ $json.is_subscribed }}
- Operation:
Is True
- Data Type:
Boolean
Outcome:
- True Branch (✅): Add contact to the “newsletter subscribers” list.
- False Branch (❌): Do not add to the list.
Example 7: Event Date in the Future 🗓️
Scenario: Send a pre-event reminder only if the event date is still in the future.
Inputs: An event management system provides eventDate
(e.g., “2023-12-31T10:00:00Z”).
Data Example: {"eventName": "Product Launch", "eventDate": "2024-03-15T09:00:00Z"}
If Node Configuration:
- Value 1:
{{ $json.eventDate }}
- Operation:
Greater Than
- Value 2:
{{ now() }}
(This n8n expression gets the current date/time) - Data Type:
DateTime
Outcome:
- True Branch (✅): Send the pre-event reminder.
- False Branch (❌): Do nothing (event has passed or is today).
Example 8: Low Inventory Alert 📦🔽
Scenario: Trigger a reorder process if product inventory drops below a critical level (e.g., 10 units).
Inputs: An inventory system provides currentStock
.
Data Example: {"productId": "PROD456", "productName": "Widget X", "currentStock": 5}
If Node Configuration:
- Value 1:
{{ $json.currentStock }}
- Operation:
Less Than
- Value 2:
10
- Data Type:
Number
Outcome:
- True Branch (✅): Trigger reorder automation (e.g., create a purchase order, send alert to purchasing team).
- False Branch (❌): No action needed (stock is sufficient).
Example 9: Case-Insensitive Category Match 🏷️
Scenario: Process products differently if their category contains “electronics”, regardless of capitalization.
Inputs: A product database provides productCategory
.
Data Example: {"itemId": "ABC", "itemName": "Smartphone", "productCategory": "ELECTRONICS - Mobile"}
If Node Configuration:
- Value 1:
{{ $json.productCategory.toLowerCase() }}
(This n8n expression converts the value to lowercase) - Operation:
Contains
- Value 2:
electronics
- Data Type:
String
- Case Sensitive: ❌ (This is key, as we already lowercased Value 1)
Outcome:
- True Branch (✅): Apply electronics-specific pricing rules or marketing campaigns.
- False Branch (❌): Process as a regular product.
Example 10: Comparing Two Dynamic Values ⚖️
Scenario: Approve a budget request only if the requested amount is less than the department’s allocated budget.
Inputs: A budget request system provides requestedAmount
and allocatedBudget
.
Data Example: {"requestId": "REQ101", "department": "Marketing", "requestedAmount": 5000, "allocatedBudget": 7500}
If Node Configuration:
- Value 1:
{{ $json.requestedAmount }}
- Operation:
Less Than
- Value 2:
{{ $json.allocatedBudget }}
- Data Type:
Number
Outcome:
- True Branch (✅): Automatically approve the budget request.
- False Branch (❌): Send the request for manual review/escalation.
Advanced Tips for Mastering the If Node ✨
-
Chaining If Nodes for AND/OR Logic:
- AND Logic: To check if Condition A AND Condition B are true, place an If node for Condition B on the “True” branch of the If node for Condition A.
- OR Logic: To check if Condition A OR Condition B is true, process both through separate If nodes. If either’s “True” branch leads to the same outcome, connect both “True” branches to that next step. Or, use a “Merge” node after both If nodes to bring items back together.
- For more complex AND/OR logic, consider using a Code node (JavaScript) or a Set node with a complex expression to evaluate multiple conditions and output a single boolean (true/false) value, which can then feed into a simple If node.
-
Expressions are Your Best Friend: Don’t limit yourself to static values. Leverage n8n’s powerful expressions to dynamically fetch and manipulate data (
{{ $json.propertyName }}
,{{ now() }}
,{{ $item(0).$json.value }}
). This makes your workflows incredibly flexible. -
Error Handling with If: You can use an If node to check if an API call returned an error message or a specific status code, then route the workflow to an error logging system or retry mechanism.
-
Test Thoroughly: Always test your If node configurations with various input data (expected, edge cases, invalid data) to ensure it behaves as expected on both the True and False branches. Use the “Test Workflow” feature and examine the output of the If node carefully.
Conclusion: Build Smarter, Not Harder! 🚀
The n8n If node is an indispensable tool for building robust, intelligent, and flexible automation workflows. By mastering its core components and understanding how to apply conditional logic effectively, you can transform your n8n workflows from simple sequential tasks into dynamic decision-makers.
Whether you’re filtering data, routing information, or triggering actions based on specific criteria, the If node is your go-to solution. Start experimenting with these examples in your own n8n instance and unlock the true power of conditional automation! Happy building! ✨