如何通过Notion API向数据库插入数据?

thm*_*tew 9 notion-api

我对 Notion 非常陌生,我想在项目中使用该 API。

我应该如何在 Notion 数据库中插入数据?我知道如何读取有关数据库的信息,我知道如何更新架构,我知道如何从数据库检索数据,但我不知道如何向数据库插入数据或从数据库中删除数据。

谢谢。

小智 11

每个数据代表一个页面。所以你想将一个页面导入到数据库中。这里它告诉你如何导入页面https://developers.notion.com/reference/post-page

exports.newEntryToDatabase = async function (name, description) {
  const response = await notion.pages.create({
    parent: {
      database_id: process.env.NOTION_API_DATABASE,
    },
    properties: {
      Name: {
        title: [
          {
            text: {
              content: name,
            },
          },
        ],
      },
      Description: {
        rich_text: [
          {
            text: {
              content: description,
            },
          },
        ],
      },
    },
  });

  return response;
};
Run Code Online (Sandbox Code Playgroud)