8
n8n 中文网amn8n.com

在 Notion 数据库中归档空白页面

中级

这是一个Building Blocks领域的自动化工作流,包含 10 个节点。主要使用 If, Cron, Notion, Function, SplitInBatches 等节点。 归档 Notion 数据库中的空白页面

前置要求
  • Notion API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移

无法加载工作流预览

导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": 115,
  "name": "在 Notion 数据库中归档空白页面",
  "nodes": [
    {
      "name": "获取所有数据库",
      "type": "n8n-nodes-base.notion",
      "position": [
        240,
        300
      ],
      "parameters": {
        "resource": "database",
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "notionApi": {
          "id": "36",
          "name": "Notion account"
        }
      },
      "typeVersion": 2
    },
    {
      "name": "获取所有数据库页面",
      "type": "n8n-nodes-base.notion",
      "position": [
        420,
        300
      ],
      "parameters": {
        "simple": false,
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": "={{$json[\"id\"]}}"
      },
      "credentials": {
        "notionApi": {
          "id": "36",
          "name": "Notion account"
        }
      },
      "typeVersion": 2
    },
    {
      "name": "获取页面块",
      "type": "n8n-nodes-base.notion",
      "position": [
        1180,
        280
      ],
      "parameters": {
        "blockId": "={{$json[\"id\"]}}",
        "resource": "block",
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "notionApi": {
          "id": "36",
          "name": "Notion account"
        }
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "name": "处理块",
      "type": "n8n-nodes-base.function",
      "position": [
        1360,
        280
      ],
      "parameters": {
        "functionCode": "let returnData = {\n  json: {\n    toDelete: false,\n    pageID: $node[\"SplitInBatches\"].json[\"id\"],\n  }\n};\n\nif (!items[0].json.id) {\n  returnData.json.toDelete = true;\n  return [returnData];\n}\n\nfor (item of items) {\n  \n  let toDelete = false;\n\n  let type = item.json.type;\n  let data = item.json[type];\n\n  if (!toDelete) {\n    if (data.text.length == 0) {\n      toDelete = true;\n    } else {\n      returnData.json.toDelete = false;\n      break;\n    }\n  }\n\n  returnData.json.toDelete = toDelete;\n}\n\nreturn [returnData];"
      },
      "typeVersion": 1
    },
    {
      "name": "分批处理",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1000,
        280
      ],
      "parameters": {
        "options": {},
        "batchSize": 1
      },
      "typeVersion": 1
    },
    {
      "name": "检查空属性",
      "type": "n8n-nodes-base.function",
      "position": [
        600,
        300
      ],
      "parameters": {
        "functionCode": "for (item of items) {\n\n  let toDelete = false;\n  for (const key in item.json.properties) {\n    let type = item.json.properties[key].type;\n    let data = item.json.properties[key][type];\n    \n    if (!data || data.length == 0) {\n      toDelete = true;\n    } else {\n      toDelete = false;\n      break;\n    }\n  }\n\n  item.json.toDelete = toDelete;\n}\n\nreturn items;"
      },
      "typeVersion": 1
    },
    {
      "name": "归档页面",
      "type": "n8n-nodes-base.notion",
      "position": [
        1760,
        260
      ],
      "parameters": {
        "pageId": "={{$json[\"pageID\"]}}",
        "operation": "archive"
      },
      "credentials": {
        "notionApi": {
          "id": "36",
          "name": "Notion account"
        }
      },
      "typeVersion": 2
    },
    {
      "name": "如果需删除",
      "type": "n8n-nodes-base.if",
      "position": [
        1560,
        280
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"toDelete\"]}}",
              "value2": true
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "name": "如果属性为空",
      "type": "n8n-nodes-base.if",
      "position": [
        760,
        300
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"toDelete\"]}}",
              "value2": true
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "name": "每天凌晨2点",
      "type": "n8n-nodes-base.cron",
      "position": [
        80,
        300
      ],
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 2
            }
          ]
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {},
  "connections": {
    "If toDelete": {
      "main": [
        [
          {
            "node": "Archive Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Blocks": {
      "main": [
        [
          {
            "node": "If toDelete",
            "type": "main",
            "index": 0
          },
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "Get Page Blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every day @ 2am": {
      "main": [
        [
          {
            "node": "Get All Databases",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Page Blocks": {
      "main": [
        [
          {
            "node": "Process Blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get All Databases": {
      "main": [
        [
          {
            "node": "Get All Database Pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Empty Properties": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get All Database Pages": {
      "main": [
        [
          {
            "node": "Check for empty properties",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for empty properties": {
      "main": [
        [
          {
            "node": "If Empty Properties",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 构建模块

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量10
分类1
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流