How to add to my Google Sheet only data that doesn't exist

Hi Guys, would like to add to my Google Sheet only the new rows (that it doesn’t find into my Google Sheets); I tried the merge node with “Remove Key Matches”, but I have all the datas returned (I put 3 rows in my Google Sheet for the test and some ID that I know I get from the HTTP request). Do you have any idea on how to solve this ? Thanks !


Hey @jeremy_FRANCOIS!

Welcome to the community :sparkling_heart:

Is the data from the HTTP Request node and the Google Sheet node exactly the same? I would check for any whitespace that can cause the result.

Another approach for this is to use use the Lookup operation in the Google Sheets node. You can add an IF node after this Google Sheets node and check if the incoming data is empty or not. Based on the output, you can proceed with the workflow. Here’s a small workflow. If you check the Settings tab in the Google Sheets node, you will notice that I’ve switched the Always Output Data to true. This will return an empty object and keep your workflow running.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "lookup",
        "lookupColumn": "ID",
        "lookupValue": "1",
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "alwaysOutputData": true,
      "credentials": {
        "googleSheetsOAuth2Api": "Google [email protected]"
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"ID\"]}}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "name": "IF empty?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ],
      "alwaysOutputData": false
    },
    {
      "parameters": {},
      "name": "Add to Sheet",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        150
      ]
    },
    {
      "parameters": {},
      "name": "Already in Sheet",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "IF empty?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF empty?": {
      "main": [
        [
          {
            "node": "Add to Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Already in Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope this helps :slight_smile:

Thanks Harshil, I will have a look !

1 Like

Hi @harshil1712 , is that normal that I don’t get any data for the true output ? (I see 10 items and my goal is to add them to the sheet)

And I checked my ID for the merge node but I don’t have any whitespace but with the lookup it works (compare if the ID exists or not). :slight_smile:

It works finally ! I had to put “id” into the merge as a string and not use the json id (from the output data). Thanks !!Screenshot 2021-08-26 at 19.02.27

1 Like

Awesome! I am glad that you found the solution. I don’t know how I missed it :sweat_smile:

Anyways, have fun :slight_smile:

1 Like