Getting error "Multiple matching items for item [1] [item 1]" for node after merge node but works if placed before the merge

Hi community,
I am getting error “Multiple matching items for item [1] [item 1]” for node after merge node but works if placed before the merge.
I did some trial and error and noted that the problem lies within the “google sheet” node but I am not sure why.

Here’s the info I found:

  • If I remove the google sheet node, it works fine, both the gmail label nodes (before and after the merge node) would process the message ID fine.
  • If I add the google sheet node back, the gmail label node before the merge node would still work BUT the one after the merge node would then fail…

Error messsage is: Multiple matching items for item [1] [item 1]

Information on your n8n setup

  • **n8n version:1.95.3
  • **Running n8n via (Docker self hosted]
  • **Operating system:ubuntu

Here’s my workflow:
Note, the original WF is bigger than that, but to prevent confusion, I have deleted other nodes to simplify and ensure the error can still be replicated.

{
“nodes”: [
{
“parameters”: {},
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
-360,
800
],
“id”: “135f739d-3be5-4c38-a96d-718987c384cd”,
“name”: “When clicking ‘Execute workflow’”
},
{
“parameters”: {
“operation”: “getAll”,
“limit”: 2,
“simple”: false,
“filters”: {
“labelIds”: [
“Label_127”
],
“receivedAfter”: “2024-07-01T00:00:00”
},
“options”: {
“downloadAttachments”: true
}
},
“type”: “n8n-nodes-base.gmail”,
“typeVersion”: 2.1,
“position”: [
-140,
800
],
“id”: “adb22c10-4e79-4efe-adcd-9c2d28637352”,
“name”: “Gmail”,
“webhookId”: “cf442f14-042a-4366-aa0c-9acf7168b54e”,
“credentials”: {
“gmailOAuth2”: {
“id”: “UNQAFDOzPufSLXOc”,
“name”: “Gmail account”
}
}
},
{
“parameters”: {
“inputDataFieldName”: “attachment_0”,
“name”: “={{ $json[‘Subjet-trimmed’] }}-{{ $binary.attachment_0.fileName }}-{{ $json.date_trimmed }}”,
“driveId”: {
“__rl”: true,
“mode”: “list”,
“value”: “My Drive”
},
“folderId”: {
“__rl”: true,
“value”: “1nwKrjNdGR02bFBornw6ICIzn6eYhiUMb”,
“mode”: “list”,
“cachedResultName”: “Invoice-from-Gmail”,
“cachedResultUrl”: “https://drive.google.com/drive/folders/1nwKrjNdGR02bFBornw6ICIzn6eYhiUMb
},
“options”: {}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
520,
800
],
“id”: “62b8aeda-bfad-4c79-bfdc-b912f6d5dbb5”,
“name”: “Google Drive”,
“credentials”: {
“googleDriveOAuth2Api”: {
“id”: “2FWG5hRWNEn1WXvp”,
“name”: “Google Drive account”
}
}
},
{
“parameters”: {
“textsWithManipulations”: {
“textsWithManipulationsValues”: [
{
“dataSources”: {
“dataSource”: [
{
“text”: “={{ $json.subject }}”,
“destinationKey”: “Subjet-trimmed”
}
]
},
“manipulations”: {
“manipulation”: [
{
“action”: “replace”,
“substring”: “Important Notice: Your”,
“value”: “=”
}
]
}
}
]
}
},
“type”: “n8n-nodes-text-manipulation.textManipulation”,
“typeVersion”: 1,
“position”: [
80,
700
],
“id”: “ccb698c4-06c2-4c2b-84f2-954111728252”,
“name”: “Subject_regextrim”
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “a20a26ba-bc6d-42d0-8ccb-6bce8615854d”,
“name”: “date_trimmed”,
“value”: “={{ $json.headers.date.match(/(\d{1,2}\s+\w+\s+\d{4})/)?.[1] }}”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
80,
900
],
“id”: “2fac489e-b0de-4dcd-a3bb-f86eec3442ff”,
“name”: “Date_regextrim”
},
{
“parameters”: {
“mode”: “combine”,
“combineBy”: “combineByPosition”,
“options”: {}
},
“type”: “n8n-nodes-base.merge”,
“typeVersion”: 3.2,
“position”: [
300,
800
],
“id”: “a57b29e7-e343-4a63-911e-3b11237af429”,
“name”: “Merge”
},
{
“parameters”: {
“mode”: “runOnceForEachItem”,
“jsCode”: “// Access the current item’s data from the .json property\nconst rawMapping = item.json.mapping;\nconst text = item.json.text;\n\n// Parse the mapping string into a JSON array\nlet mapping;\ntry {\n mapping = JSON.parse(rawMapping);\n} catch (error) {\n // If parsing fails, return an object with an error message\n return { json: { error: "Invalid mapping format: " + error.message } };\n}\n\n// Validate inputs\nif (typeof text !== ‘string’) {\n return { json: { error: "Input ‘text’ must be a string." } };\n}\nif (!Array.isArray(mapping)) {\n return { json: { error: "Parsed ‘mapping’ must be an array." } };\n}\n\n// Perform replacements for each entry in the mapping array\nlet modifiedText = text;\nfor (const entry of mapping) {\n // Ensure the entry has valid find and replace properties\n if (entry.find !== undefined && entry.replace !== undefined && entry.find !== ‘’) {\n const findStr = String(entry.find);\n const replaceStr = String(entry.replace);\n \n // Use split and join for a robust, literal string replacement\n modifiedText = modifiedText.split(findStr).join(replaceStr);\n }\n}\n\n// Return a single object, not an array\nreturn {\n json: {\n modifiedText: modifiedText\n }\n};”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
2060,
500
],
“id”: “4f6d9ec5-cdb4-4cb4-8d99-75cf52d10e95”,
“name”: “Code1”,
“executeOnce”: false,
“onError”: “continueRegularOutput”
},
{
“parameters”: {
“mode”: “combine”,
“combineBy”: “combineByPosition”,
“options”: {}
},
“type”: “n8n-nodes-base.merge”,
“typeVersion”: 3.1,
“position”: [
1840,
600
],
“id”: “22eef1b3-5b9e-4897-8aa8-aeab397ed916”,
“name”: “Merge1”,
“executeOnce”: false
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “55ba6461-ec26-4314-acc8-5670a3614fae”,
“name”: “text”,
“value”: “={{ $json.data }}”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
1620,
800
],
“id”: “bb1176e1-4bd1-4f65-89d3-9c02c458a6e5”,
“name”: “Edit Fields3”
},
{
“parameters”: {
“operation”: “download”,
“fileId”: {
“__rl”: true,
“value”: “={{ $json.id }}”,
“mode”: “id”
},
“options”: {
“googleFileConversion”: {
“conversion”: {
“docsToFormat”: “application/rtf”
}
}
}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
740,
800
],
“id”: “4a3b3942-5607-4b7b-a5ab-5ef0ee129b33”,
“name”: “Google Drive1”,
“credentials”: {
“googleDriveOAuth2Api”: {
“id”: “2FWG5hRWNEn1WXvp”,
“name”: “Google Drive account”
}
}
},
{
“parameters”: {
“operation”: “pdf”,
“options”: {}
},
“type”: “n8n-nodes-base.extractFromFile”,
“typeVersion”: 1,
“position”: [
960,
700
],
“id”: “403d8b9a-889a-4cb2-8b56-0266a9eaf262”,
“name”: “Extract from File”
},
{
“parameters”: {
“folderId”: “1sL6P6Asa1VOLDTGy4tF9jYG9ocaurwph”,
“title”: “={{ $(‘Google Drive1’).item.json.name }}”
},
“type”: “n8n-nodes-base.googleDocs”,
“typeVersion”: 2,
“position”: [
1180,
700
],
“id”: “c473c282-ccab-4fda-addc-3f2ceefba6fb”,
“name”: “Google Docs”,
“credentials”: {
“googleDocsOAuth2Api”: {
“id”: “yHbRJKQzyxXsPXm5”,
“name”: “Google Docs account”
}
}
},
{
“parameters”: {
“operation”: “update”,
“documentURL”: “={{ $json.id }}”,
“actionsUi”: {
“actionFields”: [
{
“action”: “insert”,
“text”: “={{ $(‘Extract from File’).item.json.text }}”
}
]
}
},
“type”: “n8n-nodes-base.googleDocs”,
“typeVersion”: 2,
“position”: [
1400,
700
],
“id”: “93d6c86d-06a8-4ec8-9b1d-ddaca5bcf0f0”,
“name”: “Google Docs1”,
“credentials”: {
“googleDocsOAuth2Api”: {
“id”: “yHbRJKQzyxXsPXm5”,
“name”: “Google Docs account”
}
}
},
{
“parameters”: {
“operation”: “deleteFile”,
“fileId”: {
“__rl”: true,
“value”: “={{ $json.id }}”,
“mode”: “id”
},
“options”: {}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
960,
900
],
“id”: “62681ceb-6671-4728-825b-b3c8318c5238”,
“name”: “Google Drive3”,
“credentials”: {
“googleDriveOAuth2Api”: {
“id”: “2FWG5hRWNEn1WXvp”,
“name”: “Google Drive account”
}
}
},
{
“parameters”: {
“content”: “This gmail label node which would fail”,
“height”: 460,
“width”: 740
},
“type”: “n8n-nodes-base.stickyNote”,
“typeVersion”: 1,
“position”: [
2560,
720
],
“id”: “688bb925-f944-40f9-a67c-ee60b7498141”,
“name”: “Sticky Note”
},
{
“parameters”: {
“operation”: “addLabels”,
“messageId”: “={{ $(‘Gmail’).item.json.id }}”,
“labelIds”: [
“Label_7868420187393967160”
]
},
“type”: “n8n-nodes-base.gmail”,
“typeVersion”: 2.1,
“position”: [
2620,
780
],
“id”: “e8673cb6-9968-42ef-8629-5da073e0088c”,
“name”: “Gmail Label - failed”,
“webhookId”: “72771414-f928-4d9a-a864-4f3590c3be7a”,
“executeOnce”: false,
“credentials”: {
“gmailOAuth2”: {
“id”: “UNQAFDOzPufSLXOc”,
“name”: “Gmail account”
}
}
},
{
“parameters”: {
“operation”: “addLabels”,
“messageId”: “={{ $(‘Gmail’).item.json.id }}”,
“labelIds”: [
“Label_7868420187393967160”
]
},
“type”: “n8n-nodes-base.gmail”,
“typeVersion”: 2.1,
“position”: [
2000,
960
],
“id”: “73099203-92d1-45a9-8527-b0121022963b”,
“name”: “Gmail label - success”,
“webhookId”: “7f638897-ace1-433d-a8e7-2a150e62ed29”,
“executeOnce”: false,
“credentials”: {
“gmailOAuth2”: {
“id”: “UNQAFDOzPufSLXOc”,
“name”: “Gmail account”
}
},
“notes”: “Apply n8n-processed label”
},
{
“parameters”: {
“content”: “This gmail label node before this merge1 would work”,
“height”: 420,
“width”: 520
},
“type”: “n8n-nodes-base.stickyNote”,
“typeVersion”: 1,
“position”: [
1960,
860
],
“id”: “60fdf434-f710-4b88-bc6e-525434abbdac”,
“name”: “Sticky Note1”
},
{
“parameters”: {
“documentId”: {
“__rl”: true,
“value”: “1WEC-8iQGmnG-Fb-K3RTKmh7FzM0ZffcCjRzOPoKOcFA”,
“mode”: “list”,
“cachedResultName”: “n8n-excel”,
“cachedResultUrl”: “https://docs.google.com/spreadsheets/d/1WEC-8iQGmnG-Fb-K3RTKmh7FzM0ZffcCjRzOPoKOcFA/edit?usp=drivesdk
},
“sheetName”: {
“__rl”: true,
“value”: 1701577339,
“mode”: “list”,
“cachedResultName”: “duplicate check”,
“cachedResultUrl”: “https://docs.google.com/spreadsheets/d/1WEC-8iQGmnG-Fb-K3RTKmh7FzM0ZffcCjRzOPoKOcFA/edit#gid=1701577339
},
“options”: {}
},
“type”: “n8n-nodes-base.googleSheets”,
“typeVersion”: 4.6,
“position”: [
1620,
550
],
“id”: “44ebc07b-4905-4ee9-80aa-54f42a815f6d”,
“name”: “Google Sheets”,
“executeOnce”: true,
“credentials”: {
“googleSheetsOAuth2Api”: {
“id”: “qctTiz6VNFKXs2fp”,
“name”: “Google Sheets account 2”
}
}
}
],
“connections”: {
“When clicking ‘Execute workflow’”: {
“main”: [
[
{
“node”: “Gmail”,
“type”: “main”,
“index”: 0
}
]
]
},
“Gmail”: {
“main”: [
[
{
“node”: “Subject_regextrim”,
“type”: “main”,
“index”: 0
},
{
“node”: “Date_regextrim”,
“type”: “main”,
“index”: 0
}
]
]
},
“Google Drive”: {
“main”: [
[
{
“node”: “Google Drive1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Subject_regextrim”: {
“main”: [
[
{
“node”: “Merge”,
“type”: “main”,
“index”: 0
}
]
]
},
“Date_regextrim”: {
“main”: [
[
{
“node”: “Merge”,
“type”: “main”,
“index”: 1
}
]
]
},
“Merge”: {
“main”: [
[
{
“node”: “Google Drive”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code1”: {
“main”: [

]
},
“Merge1”: {
“main”: [
[
{
“node”: “Code1”,
“type”: “main”,
“index”: 0
},
{
“node”: “Gmail Label - failed”,
“type”: “main”,
“index”: 0
}
]
]
},
“Edit Fields3”: {
“main”: [
[
{
“node”: “Merge1”,
“type”: “main”,
“index”: 1
},
{
“node”: “Gmail label - success”,
“type”: “main”,
“index”: 0
}
]
]
},
“Google Drive1”: {
“main”: [
[
{
“node”: “Extract from File”,
“type”: “main”,
“index”: 0
},
{
“node”: “Google Drive3”,
“type”: “main”,
“index”: 0
}
]
]
},
“Extract from File”: {
“main”: [
[
{
“node”: “Google Docs”,
“type”: “main”,
“index”: 0
}
]
]
},
“Google Docs”: {
“main”: [
[
{
“node”: “Google Docs1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Google Docs1”: {
“main”: [
[
{
“node”: “Edit Fields3”,
“type”: “main”,
“index”: 0
},
{
“node”: “Google Sheets”,
“type”: “main”,
“index”: 0
}
]
]
},
“Google Sheets”: {
“main”: [
[
{
“node”: “Merge1”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a”
}
}

Thanks all

I recommend the following:

Use Merge by key instead of Merge by position if the data isn’t perfectly aligned. If the original email (Gmail) is disconnected by Merge1, the messageId required to label the email may be lost. One solution would be to use a common property (message id) to perform a merge with:

"mode": "mergeByKey",
"propertyName1": "id",
"propertyName2": "id"

This ensures that the Gmail message data is preserved and available in Gmail. Label - failed.

Trace key values ​​such as messageId in a Function or Set node before performing complex merges. Add a Set node before Merge1 that explicitly stores the message ID in a clear property, for example:

{
"name": "storeMessageId",
"parameters": {
"assignments": [
{
"name": "gmail_id",
"value": "={{ $('Gmail').item.json.id }}"
}
]
}
}

Then, in Gmail Label - failed, change messageId to:
={{ $json.gmail_id }}

and finally, use Keep Only Set in intermediate nodes with caution.
If a “Keep Only Set” is used in any node and the message ID is not included, it will be lost. Make sure the Gmail message ID property is passed through without being deleted.

Thanks @Erick_Torres .
That helped a lot and gave me more understanding of how the info pass through.

I was under the impression data are passed on from node to node but realized that’s not the case, some info got lost when using set node and merge node.

Regards,
Bong