Route, branch and merge appointment records in n8n
Route supported and unsupported requests, test an empty branch and merge records on an explicit key.
By Invicly Tech, , in n8n, AI Automation and Voice Agents. About 9 minutes to read.
In short
Real requests are not all alike, so a workflow needs to send them down different paths. The If node splits items into true and false, and the Switch node sends them to one of many outputs. The Merge node later joins branches back together, ideally on a key you choose.
Think of it like this: A branch is a sorting desk in a post room: letters go to different trays, and a merge is a clerk matching each letter with its parcel by reference number.
Explained simply
Not every request should be treated the same way. A haircut booking, a colour booking and a request for something the salon does not offer all need different handling. In n8n you split the flow into branches, and each branch handles one kind of item.
The If node asks a yes or no question about each item and sends it to the true or false output. The Switch node is for more than two outcomes. It has a rule for each output, and a fallback output for anything that matches no rule. That fallback is where unsupported requests belong.
Sometimes a branch gets no items at all. The nodes after it then do not run. That is fine, but you must test it, because a workflow that works with data may behave oddly with none.
Later you may want to bring data back together, for example a request and the matching availability result. The Merge node does this. Joining on a shared field, like request_id, pairs the right records. Joining by position only works when both sides stay in step, which they often do not.
Press Play on a diagram to walk through it one step at a time.
- Switch on service
- Haircut
- Colour
- Consultation
- Fallback
- Unsupported service
- Send to review list
- If email missing
- Reject with reason
- Puts lists end to end
- No matching needed
- Output = sum of inputs
- Joins on a key such as request_id
- Choose matches only or keep unmatched
- Watch for duplicate keys
- Pairs item 1 with item 1
- Needs equal order and count
- Fragile when a branch drops items
In depth
If versus Switch
Use If for a single yes or no. Use Switch when there are several named outcomes. In Rules mode, each rule has conditions and an output. By default an item goes to the first rule that matches. There is an option to send it to all matching outputs instead, which is useful when one item needs more than one follow-up.
A Switch can also run in Expression mode, where one expression returns the number of the output. Rules mode is easier to read and review, so prefer it unless the logic is truly dynamic. Always turn on the fallback output and connect it to something visible.
- If: true and false outputs
- Switch Rules mode: one output per rule
- Option to send to all matching outputs
- Fallback output for unmatched items
Give unsupported requests a path
If an item matches no rule and there is no fallback, it simply goes nowhere, and nobody knows. That is the worst kind of failure: silent. Connect the fallback to a node that records the request, for example a data table or a list for a person to review.
A good habit is to name the path honestly, for example Unsupported service, and to count it in your checks. A run that received 10 items and handled 8 supported, 1 unsupported and 1 rejected is easy to reason about.
- Step 1Switch
No rule matches
- Step 2Fallback output
Never left unconnected
- Step 3Record request
Store with reason: unsupported service
- Step 4Review list
A person decides what to do
Testing an empty branch
When no item takes a branch, n8n does not run the nodes that follow it. A common surprise is a node after a Merge that expects data from both sides. To test, make an input where every item goes the same way and watch the execution. Nodes that did not run show no data.
If a later step must always run, such as a summary, put it after a point where data always exists, or use the node setting Always Output Data where it makes sense. Use that setting carefully: it creates an empty item, which can look like a real record.
- Make test input that skips a branch
- Unrun nodes show no data
- Always Output Data adds an empty item
- Never treat an empty item as a real record
Merge on an explicit key
The Merge node has several modes. Append puts one list after the other. Combine can join by matching fields, by position, or in all possible combinations. Choose Output Data From to decide whether to keep matches only, or keep unmatched records from one or both sides.
With matching fields, you name the key on each side, for example request_id. Records with the same value are joined. Duplicate keys on one side produce more rows, so check for them. After the merge, count the output and look for empty fields, which mark records that found no partner.
Learn it in 5 short steps
About 30m each. Track them with a timer in your plan.
- 1Branch with If and Switch~30m
- 2Send unsupported requests to their own path~30m
- 3Test what happens on an empty branch~30m
- 4Merge records by a matching key~30m
- 5Check merged output for gaps~30m
Key points
- If has two outputs, true and false. Switch has one output per rule and an optional fallback for everything else.
- Always give unsupported requests their own path, so nothing silently disappears.
- A branch with no items does not run its following nodes. Test this case on purpose.
- Merge by matching fields joins records that share a key such as request_id. Merging by position is fragile.
- After a merge, count the items and check for missing or duplicated records.
Key terms
Tap a card to flip it. 0/5 known
Examples
Switch (mode: Rules)
Output 0: {{ $json.service }} equals haircut
Output 1: {{ $json.service }} equals colour
Output 2: {{ $json.service }} equals consultation
Fallback: Extra output -> Unsupported path
Merge (mode: Combine, by matching fields)
Input 1 field: request_id
Input 2 field: request_id
Output type: Keep matchesSwitch rules for a salon request. Rules are checked in order.
Route three requests and an unsupported one
Four synthetic requests arrive: haircut, colour, consultation and massage. The Switch has rules for the first three, and the fallback catches massage. Expect output counts of 1, 1, 1 and 1. If you remove the fallback, the massage request disappears, and the total handled is 3 of 4.
Input: haircut, colour, consultation, massage
Switch rules: haircut -> 0, colour -> 1, consultation -> 2
Fallback -> Unsupported path
Counts: 1 + 1 + 1 + 1 = 4 of 4Merge requests with availability by request_id
One branch holds requests, another holds availability results keyed by request_id. Merge them by matching fields and keep matches only. Then compare counts: 4 requests in and 3 merged rows tells you one request had no availability result and needs attention.
Merge: Combine > Matching fields
Input 1: request_id Input 2: request_id
Output: Keep matches
Check: requests 4, availability 3, merged 3 -> 1 unmatched, inspect itQuick reference
- If = two outputs. Switch = one output per rule plus a fallback.
- Connect the Switch fallback to something visible.
- Nodes after an empty branch do not run.
- Merge by matching fields uses an explicit key; avoid position unless orders are certain.
- Check counts after every merge: in, out and unmatched.
- Duplicate keys on one side multiply output rows.
- Always Output Data creates an empty item; use with care.
Common mistakes
- No fallback on a Switch, so unknown services vanish with no trace.
- Merging by position after one branch dropped an item, which pairs the wrong records.
- Never testing an empty branch and assuming the next node still produces output.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Add an If node that sends requests with a non-empty email to true and the rest to false.
- Exercise 2medium
Build a Switch for haircut, colour and consultation with a fallback, and test with a massage request.
- Exercise 3hard
Merge requests with availability on request_id, keep unmatched requests, and report which requests have no availability.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is the difference between Filter and If?
- Filter keeps matching items and drops the rest. If sends matching items one way and the others another way, so nothing is lost.
- Why does my Merge output look doubled?
- A key probably appears more than once on one side, so each match creates a row. Remove duplicates first or choose a unique key.
- Can one item go to two Switch outputs?
- Yes, if you enable the option to send data to all matching outputs.