Notion Trigger not working with Split in Batches (for auto-numbering)

I want to build auto-numbering in a Notion database. I catch new records with the Notion trigger and want to run a loop: read saved “current number” from another source and increment it, save this number to the _id property in Notion.

So i have to build a loop with the Split in Batches node. The problem, it’s not working in active mode. Just nothing happens when I add new records.

So i tried some experiments with a simple case - just to set a fixed number in the _id property

The top workflow works ok whith any new records within the polling interval.
The bottom workflow doesn’t work as a trigger. When I run it, the last record is processed, as usual.

Here’s the code

{
  "name": "Notion Trigger Loop",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        70,
        1510
      ],
      "disabled": true
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "event": "pageAddedToDatabase",
        "databaseId": "80385515-b06c-4d30-9bf2-b2a373d14a9d",
        "simple": false
      },
      "name": "Notion Trigger1",
      "type": "n8n-nodes-base.notionTrigger",
      "typeVersion": 1,
      "position": [
        100,
        1150
      ],
      "credentials": {
        "notionApi": {
          "id": "2",
          "name": "Notion for n8n course"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "record_id|number",
              "numberValue": 10
            }
          ]
        }
      },
      "name": "Notion4",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        530,
        1310
      ],
      "credentials": {
        "notionApi": {
          "id": "2",
          "name": "Notion for n8n course"
        }
      }
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches1",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        320,
        1150
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "80385515-b06c-4d30-9bf2-b2a373d14a9d",
        "options": {}
      },
      "name": "Get Notion Pages id-s",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        920,
        1700
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "event": "pageAddedToDatabase",
        "databaseId": "80385515-b06c-4d30-9bf2-b2a373d14a9d",
        "simple": false
      },
      "name": "Notion Trigger",
      "type": "n8n-nodes-base.notionTrigger",
      "typeVersion": 1,
      "position": [
        100,
        930
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "record_id|number",
              "numberValue": 10
            }
          ]
        }
      },
      "name": "Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        300,
        930
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      },
      "disabled": true
    }
  ],
  "connections": {
    "Notion Trigger1": {
      "main": [
        [
          {
            "node": "SplitInBatches1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches1": {
      "main": [
        [
          {
            "node": "Notion4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion4": {
      "main": [
        [
          {
            "node": "SplitInBatches1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        []
      ]
    },
    "Notion Trigger": {
      "main": [
        [
          {
            "node": "Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "id": 28
}

Are you activating the workflow? Because if you execute the workflow via de UI (test mode), the node only returns the last record in the database. This is meant for testing purposes only. If you active the workflow (production mode), n8n poll the data from the API using the unit of time you selected from the UI.

@RicardoE105 Yes, of course.
Let me summorize my experiment with loops:

  1. When active, the simple loop (without Split) works, it catches all the new records.
  2. When active, the loop with Split doesn’t fire on any number of new records
  3. To check, if the workflow from (2) is valid, I execute it. It works, processing the last new record

So the problem is that the data from the Trigger doesn’t work properly with the Split node. Actually this means we can’t work with the trigger in many use cases. Like processing the data and saving it to the file. Or auto-numbering. Or processing and saving in a Database. Or synking with other services. All of them require looping.

Don’t know how, but the Split thing seems to work. Don’t know why it didn’t work yesterday. I’ll conduct some more tests.

1 Like

So far I know for sure one thing. Notion trigger MAY NOT catch all the new items. I run many small experiments. And when added multiple rows, some of them were not processed.

Like here. They were added in a couple of seconds

Another case. I think, it’s some edge cases either for notion timer of for n8n timer

@RicardoE105, can you have a look at this problem? I know you worked with Notion a lot

What poll time are you using?

Does it or does not work with Split in Batches? The Split in Batches node should not be an issue. And you probably do not need it for most use cases since n8n automatically iterate for as many inputs as the node has.

Can you record a small video where I can see the issue?

I use 1 min poll time.

The problem is not in Split in batches. Because in general it works.
Please take a look, 2 records are not processed:

I have to use Split in Batches, because I have multiple operations in the loop. If I counted on automatical iteration, it would iterate onle the first node in the loop, I guess. I marked it with red:

Another test also gave one unchanged record, whose timing was on the edge, I guess

Here is the Notion page I worked with:

And here is the workflow:

{
  "name": "Notion Trigger Test",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        160,
        140
      ],
      "disabled": true
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "event": "pageAddedToDatabase",
        "databaseId": "80385515-b06c-4d30-9bf2-b2a373d14a9d",
        "simple": false
      },
      "name": "Notion Trigger",
      "type": "n8n-nodes-base.notionTrigger",
      "typeVersion": 1,
      "position": [
        150,
        480
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$node[\"SplitInBatches\"].json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Formula_id|rich_text",
              "textContent": "={{$node[\"SplitInBatches\"].json[\"properties\"][\"Formula\"][\"formula\"][\"string\"]}}"
            },
            {
              "key": "item_id|number",
              "numberValue": "={{$json[\"current number\"]}}"
            }
          ]
        }
      },
      "name": "Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1510,
        630
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        990,
        460
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "f6167e5d-fe75-4ec6-ac70-7d8ff88a9fb8",
        "options": {}
      },
      "name": "Notion1",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        430,
        300
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "database_id",
              "value": "={{$json[\"parent\"][\"database_id\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        430,
        480
      ]
    },
    {
      "parameters": {
        "mode": "keepKeyMatches",
        "propertyName1": "database_id",
        "propertyName2": "database_id"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        620,
        320
      ]
    },
    {
      "parameters": {
        "mode": "passThrough",
        "output": "input2"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        790,
        460
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "pageId": "={{$node[\"Merge\"].json[\"id\"]}}"
      },
      "name": "Get Current Number",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1150,
        630
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$node[\"Merge\"].json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "current number|number",
              "numberValue": "={{$node[\"Get Current Number\"].json[\"current number\"]+1}}"
            }
          ]
        }
      },
      "name": "Inc Current Number",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1320,
        630
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "Notion account"
        }
      }
    }
  ],
  "connections": {
    "Notion Trigger": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          },
          {
            "node": "Notion1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "Get Current Number",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          },
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Number": {
      "main": [
        [
          {
            "node": "Inc Current Number",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inc Current Number": {
      "main": [
        [
          {
            "node": "Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "id": 30
}

@RicardoE105I I seem to find the problem. If the trigger fired at some minute, it won’t fire in the rest of this minute, if new records added. You can see that I added some data in the same minute the process started. And it just didn’t see the new data (red rectangles). When I waited, it was fine (green rectangles)

So, as long as you do not add data the exact minute the trigger was activated, you should be fine?

I think, yes — the errors happens not always, but when happened I saw this difference in updated time.

My guess is that the “lasr updated time” has some issues to be used as a trigger event.

Maybe there shold be some other approach. Such as storing pages id-s somewhere and comparing them by polling with current pages in the database.

Fot now we have evidences that not all new items are seen by the trigger.