0

我在 Notion 中有一个工作区,我用它来为我在 Github 上的应用程序做笔记。

我想添加一个数据库,该数据库将使用 beta Notion API 显示来自不同来源(包括 Github)的一些下载统计信息。

现在我可以在数据库末尾添加信息就好了,但我不明白如何删除之前发布的内容。或者如果可以的话,甚至更新它。

这是我到目前为止所拥有的:

import { Client } from "@notionhq/client";
import dotenv from "dotenv";
import { Octokit } from "@octokit/rest";

dotenv.config();

const octokit = new Octokit();

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

const databaseId = process.env.NOTION_DATABASE_ID;

async function addEntry(release, name, download_count, tag) {
  try {
    await notion.request({
      path: "pages",
      method: "POST",
      body: {
        parent: { database_id: databaseId },
        properties: {
          Version: {
            title: [
              {
                text: {
                  content: release,
                },
              },
            ],
          },
          Name: {
            rich_text: [
              {
                text: {
                  content: name,
                },
              },
            ],
          },

          "Download Count": {
            type: "number",
            number: download_count,
          },
          Tags: {
            multi_select: [{ name: "Github" }, { name: tag }],
          },
        },
      },
    });
    console.log("Success! Entry added.");
  } catch (error) {
    console.error(error.body);
  }
}

(async () => {
  const latest_release = await octokit.repos.listReleases({
    owner: "ShadowMitia",
    repo: "steam_randomiser",
  });
  const releases = latest_release.data;

  let github_downloads = {};

  for (let release of releases) {
    for (let asset of release.assets) {
      console.log(release["tag_name"], asset["name"], asset["download_count"]);
      //   github_downloads[asset["label"]];
      addEntry(
        `${release["tag_name"]}`,
        `${asset["name"]}`,
        asset["download_count"],
        asset["name"].includes("linux") ? "Linux" : "Windows"
      );
    }
  }
})();
4

1 回答 1

0

删除(归档)数据库中的页面。将archive参数设置为 true。

curl --location --request PATCH 'https://api.notion.com/v1/pages/YOUR_PAGE_ID' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_BOT_TOKEN' \
--data'{
    "parent":{

      "database_id":"YOUR_DATABASE_ID"

   },
   "archived": true,
   "properties":{

      "Name":{

         "title":[

            {

               "text":{

                  "content":"A Test Page"

               }

            }

         ]

      },
        "Email": {
        "email": "hello@test.com"
       },
       "multiselect_tags": { 
            "type": "multi_select",
            "multi_select":[{
                        "name": "Duc Loi Market"
                    },
                    {
                        "name": "Rainbow Grocery"
                    }]
        }
    }

}'

要清除页面中的数据,您可以根据要更新的属性将数据设置为空或 null。例如,如果您有一个数组,您可以将属性设置为一个空数组。

        "multiselect_tags": { 
            "type": "multi_select",
            "multi_select":[ {
                        "name": "Duc Loi Market"
                    },
                    {
                        "name": "Rainbow Grocery"
                    }
                ]
            }
    }

//Empty a multi_select property

        "multiselect_tags": { 
            "type": "multi_select",
            "multi_select":[]
        }

如果属性是字符串,例如 email 属性,则将其设置为null

        "Email": {
        "email": "hello@test.com"
       }

//Empty the value of the email property on a page
        "Email": {
        "email": null
       }
于 2021-07-30T18:38:58.963 回答