Notion database page "Get All" not supporting multiple input items

Hi,

I seem to be running into an issue where my Notion node is only getting one item from the previous input instead of iterating through all the items from the previous node as I was expecting. This is not an issue with the Notion node that is creating new database pages but it is when using the Notion node that executes the “Get All” operation on the database page resource.

Any help would be greatly appreciated.

{
  "nodes": [
{
  "parameters": {
    "httpMethod": "POST",
    "path": "592c697b-60cf-4ba0-89b0-a957d7f25d32",
    "options": {
      "responseData": ""
    }
  },
  "name": "Webhook",
  "type": "n8n-nodes-base.webhook",
  "typeVersion": 1,
  "position": [
    80,
    -50
  ],
  "webhookId": "592c697b-60cf-4ba0-89b0-a957d7f25d32"
},
{
  "parameters": {},
  "name": "Email Team Members",
  "type": "n8n-nodes-base.noOp",
  "typeVersion": 1,
  "position": [
    1140,
    110
  ]
},
{
  "parameters": {
    "resource": "databasePage",
    "operation": "getAll",
    "databaseId": "286cf9bb-97ce-4301-a311-3a128f165973",
    "options": {
      "filter": {
        "singleCondition": {
          "key": "Email|email",
          "condition": "equals",
          "multiSelectValue": [],
          "emailValue": "={{$json[\"email\"]}}"
        }
      }
    }
  },
  "name": "Query User",
  "type": "n8n-nodes-base.notion",
  "typeVersion": 1,
  "position": [
    490,
    100
  ],
  "alwaysOutputData": true,
  "retryOnFail": false,
  "executeOnce": false,
  "notesInFlow": false,
  "credentials": {
    "notionApi": "n8n Oasis Workflows"
  }
},
{
  "parameters": {
    "functionCode": "const newItems = [];\n\nfor (const item of items[0].json.body.teamMembers) {\n  newItems.push({json: item});\n}\n\nreturn newItems;\n"
  },
  "name": "For Each Team Member",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    270,
    100
  ],
  "alwaysOutputData": false
},
{
  "parameters": {
    "resource": "databasePage",
    "databaseId": "286cf9bb-97ce-4301-a311-3a128f165973",
    "propertiesUi": {
      "propertyValues": [
        {
          "key": "Name|title",
          "title": "={{$node[\"For Each Team Member\"].json[\"name\"]}}",
          "multiSelectValue": [],
          "peopleValue": [],
          "relationValue": []
        },
        {
          "key": "Email|email",
          "multiSelectValue": [],
          "emailValue": "={{$node[\"For Each Team Member\"].json[\"email\"]}}",
          "peopleValue": [],
          "relationValue": []
        }
      ]
    }
  },
  "name": "Create Team Member",
  "type": "n8n-nodes-base.notion",
  "typeVersion": 1,
  "position": [
    930,
    110
  ],
  "credentials": {
    "notionApi": "n8n Oasis Workflows"
  }
},
{
  "parameters": {
    "conditions": {
      "boolean": [
        {
          "value1": "={{ Object.keys($json).length == 0 }}",
          "value2": true
        }
      ]
    }
  },
  "name": "If user does not exist",
  "type": "n8n-nodes-base.if",
  "typeVersion": 1,
  "position": [
    700,
    100
  ],
  "alwaysOutputData": false
}
  ],
  "connections": {
"Webhook": {
  "main": [
    [
      {
        "node": "For Each Team Member",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Query User": {
  "main": [
    [
      {
        "node": "If user does not exist",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"For Each Team Member": {
  "main": [
    [
      {
        "node": "Query User",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Create Team Member": {
  "main": [
    [
      {
        "node": "Email Team Members",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"If user does not exist": {
  "main": [
    [
      {
        "node": "Create Team Member",
        "type": "main",
        "index": 0
      }
    ]
  ]
}
  }
}

Hey @stenz!

Welcome to the community :sparkling_heart:

I created a small workflow to test it out. My workflow runs as expected and I am getting the desired results. Can you share the output you receive from the Function node? Please replace any sensitive data before sharing the output.

Side note: When you reference the values from the previous node via the Variable Selector, it will show only the first item in the Result section. However, the node processes all the items.

Hi @harshil1712,

Thanks for your help and warm welcome!

Here is the output I’ve received from the function node.

[
   {
      "name":"John Doe",
      "email":"[email protected]"
   },
   {
      "name":"Steve Smith",
      "email":"[email protected]"
   },
   {
      "name":"Jane Doe",
      "email":"[email protected]"
   }
]

I’ve attached a simpler example to illustrate the problem that I’m having. I’ve created two Notion nodes that create new objects in a database. However, one of the nodes has an additional node in front of it that makes a query to the database before it runs. I would expect the node to make a query for each user from the input data and continue to pass the those items into the create node, which means both create nodes would be running three times (one for each user). When I execute the workflow I see only 4 new entries in the database which means the creation node that has the query node in front of it is only getting executed one time instead of the three times as I was expecting.

Hope this helps makes things more clear.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        290,
        310
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "286cf9bb-97ce-4301-a311-3a128f165973",
        "options": {
          "filter": {
            "singleCondition": {
              "key": "Email|email",
              "condition": "equals",
              "emailValue": "={{$json[\"email\"]}}"
            }
          }
        }
      },
      "name": "Query User",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        860,
        480
      ],
      "alwaysOutputData": true,
      "retryOnFail": false,
      "executeOnce": false,
      "notesInFlow": false,
      "credentials": {
        "notionApi": "n8n Oasis Workflows"
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "286cf9bb-97ce-4301-a311-3a128f165973",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{$node[\"Add Input Data\"].json[\"name\"]}}"
            },
            {
              "key": "Email|email",
              "emailValue": "={{$node[\"Add Input Data\"].json[\"email\"]}}"
            }
          ]
        }
      },
      "name": "Create Team Member",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1120,
        480
      ],
      "credentials": {
        "notionApi": "n8n Oasis Workflows"
      }
    },
    {
      "parameters": {
        "functionCode": "\nconst teamMembers = [\n   {\n      \"name\":\"John Doe\",\n      \"email\":\"[email protected]\"\n   },\n   {\n      \"name\":\"Steve Smith\",\n      \"email\":\"[email protected]\"\n   },\n   {\n      \"name\":\"Jane Doe\",\n      \"email\":\"[email protected]\"\n   }\n]\n\n\nconst newItems = [];\n\nfor (const item of teamMembers) {\n  newItems.push({json: item});\n}\n\nreturn newItems;\n\nreturn data;\n"
      },
      "name": "Add Input Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        530,
        310
      ],
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "286cf9bb-97ce-4301-a311-3a128f165973",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{$node[\"Add Input Data\"].json[\"name\"]}}"
            },
            {
              "key": "Email|email",
              "emailValue": "={{$node[\"Add Input Data\"].json[\"email\"]}}"
            }
          ]
        }
      },
      "name": "Create Team Member1",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1110,
        250
      ],
      "credentials": {
        "notionApi": "n8n Oasis Workflows"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Add Input Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query User": {
      "main": [
        [
          {
            "node": "Create Team Member",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Input Data": {
      "main": [
        [
          {
            "node": "Query User",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Team Member1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks for sharing this. I tried out the workflow you shared but I couldn’t replicate the issue. Are you trying with the latest version of n8n? If you’re not using the latest version, can you please upgrade the version? We improved the node in the latest version. Hopefully that should solve your issue :slight_smile:

Hi @harshil1712,

Thanks for your response. I just upgraded the n8n version and it seems to be the same. I don’t think I have my mind fully around how to pass the data along to the last create node since the query node can return a multiple items or none at all. What I really want to do is for each user, check if they are already in the Notion database and if not create a new user.

Sorry I to have accidentally mislead you when it was a misunderstanding on my part of how the interworking of n8n worked.

Thanks again for your help.

Hey @stenz!

I don’t have an idea why the query node isn’t returning data for you. We will test it again and see if there is a bug in the node. In the meantime, I would suggest you use the Split In Batches node. This how I would carry out the flow:

  1. Fetch the email addresses
  2. Use the Split In Batches node to split the data in a batch of 1
  3. Query for the user. In the Settings tab of this node toggle Always Output Data to true
  4. Use IF node to check if the previous node returned any value
  5. If the IF node returns false, it means that the user is not there. Add the user to your Notion DB
  6. Connect this Notion node to the Split In Batches node to make a loop
  7. If the IF node returns true, we don’t want to add them. So connect the true branch to the Split In Batches node.

Let me know if this helps :slight_smile:

Hi @harshil1712,

This was very helpful, I was able to get it working!

Thanks for the support.

1 Like

That’s awesome! Have fun!