【问题标题】:Clear database to update content with Notion API清除数据库以使用 Notion API 更新内容
【发布时间】:2021-07-29 22:26:37
【问题描述】:

我在 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"
      );
    }
  }
})();

【问题讨论】:

    标签: javascript notion-api


    【解决方案1】:

    删除(归档)数据库中的页面。将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
           }
    

    【讨论】:

      猜你喜欢
      • 2022-10-02
      • 2021-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 1970-01-01
      • 2022-01-23
      相关资源
      最近更新 更多