1

通过 Notion API 文档,它提到文本配置与富文本对象相同。
在我的页面的响应中,我将 text 属性视为 -

{
"object": "page",
"id": "123",
"created_time": "2021-02-18T15:12:00.000Z",
"last_edited_time": "2021-05-15T12:37:30.830Z",
"parent": {
    "type": "database_id",
    "database_id": "456"
},
"archived": false,
"properties": {
    "Highlights": {
        "id": "jCaG",
        "type": "text",
        "text": [
            {
                "type": "text",
                "text": {
                    "content": "test 1\ntest 2",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "test 1\ntest 2",
                "href": null
            }
        ]
    }
}

我的问题是,如果text属性接受一个数组,我们可以向它添加多个文本对象吗?

我尝试对更新页面记录PATCH的请求做同样的事情,但是响应并不像预期的那样,它将所有注释切换到,即。粗体、斜体、下划线、删除线和代码块都是正确的,即使它们不在初始请求中。true

这是我在PATCH通话中发送的 JSON -

{
"object": "page",
"id": "123",
"created_time": "2021-02-18T15:12:00.000Z",
"last_edited_time": "2021-05-15T12:09:00.000Z",
"parent": {
    "type": "database_id",
    "database_id": "456"
},
"archived": false,
"properties": {
    "Highlights": {
        "id": "jCaG",
        "type": "text",
        "text": [
            {
                "type": "text",
                "text": {
                    "content": "test 1\ntest 2",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "test 1\ntest 2",
                "href": null
            },
            {
                "type": "text",
                "text": {
                    "content": "test 3",
                    "link": null
                },
                "annotations": {
                    "bold": false,
                    "italic": false,
                    "strikethrough": false,
                    "underline": false,
                    "code": false,
                    "color": "default"
                },
                "plain_text": "test 3",
                "href": null
            }
        ]
    }
}

同样的回应是——

{
"object": "page",
"id": "123",
"created_time": "2021-02-18T15:12:00.000Z",
"last_edited_time": "2021-05-15T12:37:30.830Z",
"parent": {
    "type": "database_id",
    "database_id": "456"
},
"archived": false,
"properties": {
    "Highlights": {
        "id": "jCaG",
        "type": "text",
        "text": [
            {
                "type": "text",
                "text": {
                    "content": "test 1\ntest 2",
                    "link": null
                },
                "annotations": {
                    "bold": true,
                    "italic": true,
                    "strikethrough": true,
                    "underline": true,
                    "code": true,
                    "color": "default"
                },
                "plain_text": "test 1\ntest 2",
                "href": null
            },
            {
                "type": "text",
                "text": {
                    "content": "test 3",
                    "link": null
                },
                "annotations": {
                    "bold": true,
                    "italic": true,
                    "strikethrough": true,
                    "underline": true,
                    "code": true,
                    "color": "default"
                },
                "plain_text": "test 3",
                "href": null
            }
        ]
    }
}

这里有没有人尝试过 text 属性,如果是的话,你能指导我吗?

谢谢。

4

1 回答 1

1

这是一个您可以测试使用rich_text 的调用。只要您使用名为“sample_text”的文本列设置数据库,这应该可以工作。它应该像你期望的那样工作。

curl --location --request PATCH 'https://api.notion.com/v1/pages/YOUR_PAGE_ID' \
--header 'Notion-Version: 2021-05-13' \
--header 'Authorization: Bearer YOUR_BOT_SECRET' \
--header 'Content-Type: application/json' \
--data-raw '{
   "parent":{
      "database_id":"DATABASE_ID"
   },
   "properties":{
      "Name":{
         "title":[
            {
               "text":{
                  "content":"A Test Page"
               }
            }
         ]
      },
      "sample_text":{
         "rich_text":[
            {
               "type":"text",
               "text":{
                  "content":"Some more text with "
               }
            },
            {
               "type":"text",
               "text":{
                  "content":"some"
               },
               "annotations":{
                  "italic":true,
                  "bold": false,
                  "underline": false,
                  "strikethrough": true,
                  "color": "blue"
               }
            },
            {
               "type":"text",
               "text":{
                  "content":" "
               }
            },
            {
               "type":"text",
               "text":{
                  "content":"fun"
               },
               "annotations":{
                  "bold":true,
                  "underline": false,
                  "strikethrough": false
               }
            },
            {
               "type":"text",
               "text":{
                  "content":" "
               }
            },
            {
               "type":"text",
               "text":{
                  "content":"formatting"
               },
               "annotations":{
                  "color":"pink"
               }
            }
         ]
      }
   }
}'
于 2021-06-02T00:40:39.883 回答