You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Notion API 创建页面遇400错误求助:非文本字段参数异常

解决Notion API创建页面返回400状态码的问题

核心问题

你的代码未按照Notion API规范,为每个数据库属性值添加对应类型的标识键,导致API无法正确解析属性类型,进而抛出错误。

修正后的代码

const { Client } = require("@notionhq/client");

const notion = new Client({
  auth: process.env.NOTION_TOKEN,
});

async function main() {
  try {
    await notion.pages.create({
      parent: {
        type: "database_id",
        database_id: process.env.DB_ID,
      },
      properties: {
        // 标题类型属性:必须用title键包裹文本数组
        Name: {
          title: [
            {
              text: {
                content: "Test name",
              },
            },
          ],
        },
        // URL类型属性:用url键指定完整URL(必须带http/https)
        Link: {
          url: "https://www.google.com",
        },
        // 富文本类型属性:用rich_text键包裹文本数组
        Notes: {
          rich_text: [
            {
              text: {
                content: "sample notes",
              },
            },
          ],
        },
        // 若Year为数字类型,可改为 { number: 2020 }
        Year: {
          rich_text: [
            {
              text: {
                content: "2020",
              },
            },
          ],
        },
      },
    });
    console.log("页面创建成功");
  } catch (error) {
    console.error(error);
  }
}

main();

关键修正点

  • 标题类型:数据库中标记为「标题」的属性,必须用title作为外层键,不能直接传文本数组
  • 富文本类型:数据库中标记为「文本」的属性,必须用rich_text作为外层键
  • URL类型:必须用url键指定完整的URL(包含http/https协议),否则API会拒绝
  • 其他非文本类型示例:
    • 复选框:{ checkbox: true }
    • 关系:{ relation: [{ id: "关联页面ID" }] }
    • 数字:{ number: 2020 }

额外注意事项

  • 确保代码中使用的属性名称和数据库中定义的完全一致(大小写敏感)
  • 确认你的Notion集成已获得该数据库的「编辑」权限

内容的提问来源于stack exchange,提问作者Apodictic Apple Juice

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 10:03:23