Merge by Key Binary Data Problem

Hello.

Why Merge by Key does not include the binary data also in the below example?

So i have a Input1 as you see below with Json and Table tabs.

input1

Then in Input2 i have Json Table and Binary tabs.

Then i merge them by key which key is the matchkey column that exists in both the inputs

The json structure is correct and this is the result i want BUT it does not include the binary files.

It has only Json and Table tabs.

Why is that happening?

@Mulen are there actually any binary files there? It could be that the merge node only does json data and not binary data.

@jon There are binary files in Input2. I don’t know why they aren’t merged.

If i reverse the inputs in merge node and add the node with the binary data in Input1 and the node with json data in Input2 the outcome will have binary data but the json will be wrong. It opts out the first EmailAddress and keeps the last item only.

Can someone see the example below and tell me why the binary file does not merge with the other node properly?

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://filesamples.com/samples/document/txt/sample1.txt",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        530,
        330
      ]
    },
    {
      "parameters": {
        "functionCode": "for (item of items) {\n  item.json.matchkey = 'mk';\n}\n\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        780,
        360
      ]
    },
    {
      "parameters": {
        "functionCode": "return[\n{\njson: {\n\"matchkey\": \"mk\",\n\"EmailAddress\": \"[email protected]\"\n}\n},\n{\njson: {\n\"matchkey\": \"mk\",\n\"EmailAddress\": \"[email protected]\"\n}\n}\n] "
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        730,
        130
      ]
    },
    {
      "parameters": {
        "mode": "mergeByKey",
        "propertyName1": "matchkey",
        "propertyName2": "matchkey"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1010,
        220
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          },
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey @Mulen,

It seems like there’s a bug with the Merge node. I will check it again with the team and see it that’s intentional.

In the meantime, you can refer to the following example

{
  "nodes": [
    {
      "parameters": {
        "url": "https://filesamples.com/samples/document/txt/sample1.txt",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        500
      ]
    },
    {
      "parameters": {
        "functionCode": "for (item of items) {\n  item.json.matchkey = 'mk';\n}\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        900,
        500
      ]
    },
    {
      "parameters": {
        "functionCode": "return[\n{\njson: {\n\"matchkey\": \"mk\",\n\"EmailAddress\": \"[email protected]\"\n}\n},\n{\njson: {\n\"matchkey\": \"mk\",\n\"EmailAddress\": \"[email protected]\"\n}\n}\n] "
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "mode": "mergeByKey",
        "propertyName1": "matchkey",
        "propertyName2": "matchkey"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1190,
        390
      ]
    },
    {
      "parameters": {
        "functionCode": "const bin = $node['HTTP Request'].binary;\nfor (item of items) {\n  item.binary = bin;\n}\nreturn items;"
      },
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1390,
        390
      ]
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

@harshil1712

Thank you.

Yes, keep me posted if it is actually a bug please.

Thank you for your temporary solution.