【问题标题】:How to use notion API to create tag如何使用概念 API 创建标签
【发布时间】:2021-08-25 04:59:20
【问题描述】:

我将使用 python 来跟踪来自其他网站的电影愿望清单。现在我想给每部电影一些不同的标签。但是概念参考告诉我

多选属性值对象在 multi_select 属性中包含一个多选选项值数组。

所以,我想知道如何通过 notionAPI 添加标签。或者如何使用标签模板创建数据库。

check it

【问题讨论】:

  • 我已经知道如何创建带有标签属性的页面。问题是如何创建标签。

标签: notion-api


【解决方案1】:

06/17 更新:

Select values can now be dynamically created - Notion developers


据我所知,在当前的 Notion API 版本 (2021-05-13) 中无法创建新的选择或多选选项。但好消息是,一个非官方的 python 库可以做到这一点。

notion-py是一个非官方的Python API客户端,通过模拟用户的http请求行为来实现notion操作。当您在数据库中创建或更新页面时,如果 select 或 multi-select 中的某些选项不存在,它可以添加新选项。

安装

使用 pip 安装:pip install git+https://github.com/jamalex/notion-py.git@refs/pull/294/merge

或在 requirements.txt 文件中:git+https://github.com/jamalex/notion-py.git@refs/pull/294/merge

关于使用 notion-py 在 select 或 multi-select 中添加新选项

【讨论】:

    【解决方案2】:

    假设您的 tags 属性名为“Tags”:

    curl -X POST https://api.notion.com/v1/pages \
      -H "Authorization: Bearer ${API_KEY}" \
      -H "Content-Type: application/json" \
      -H "Notion-Version: 2021-05-13" \
      --data '{
        "parent": { "database_id": "'${DATABASE_ID}'" },
        "properties": {
          "Name": {
            "title": [
              {
                "text": {
                  "content": "'${NAME}'"
                }
              }
            ]
          },
          "Tags": {
            "multi_select": [
              {"name": "'${TAG}'"}
            ]
          }
        }
      }'
    

    请注意,您必须在添加之前在数据库字段中预先填充标签名称,否则您将收到以下错误:

    {"object":"error","status":400,"code":"validation_error","message":"dcp[ is an invalid select option \"TAG NAME\"."
    

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      相关资源
      最近更新 更多