簡體   English   中英

使用概念 javascript SDK 更新概念頁面時出現驗證錯誤

[英]Validation error while updating pages in notion by using the notion javascript SDK

這是錯誤:

客戶端警告:請求失敗 { 代碼:'validation_error',消息:'body 驗證失敗。 修復一:應該定義 body.properties.body.id ,而不是undefined body.properties.body.name 應該被定義,而不是undefined body.properties.body.start 應該被定義,而不是undefined 。' } body 驗證失敗。 修復一:應該定義 body.properties.body.id ,而不是undefined body.properties.body.name 應該被定義,而不是undefined body.properties.body.start 應該被定義,而不是undefined

這是我的代碼:

async function update() {
  const res_2 = await notion.databases.query({ database_id: `${databaseId}` });

  res_2.results.forEach(async (page, index) => {
    let property_id = page.properties.Excerpt.id;
    if (index === 0) {
      try {
        const res_3 = await notion.pages.update({
          page_id: page.id,
          properties: {
            [property_id]: {
              type: "rich_text",
              rich_text: {
                "content": "hey"
              }
            }
          }
        })

      } catch (err) {
        console.log(err.message)
      }
    }
  })
}
update();

我不明白為什么會出現正文驗證錯誤以及它的來源。 有什么修復嗎?

經過一點點挖掘,我發現這個錯誤一般是在請求體中缺少參數的情況下發生的。 根據官方的 Notion 文檔,

請求正文與預期參數的架構不匹配。 檢查“消息”屬性以獲取更多詳細信息。 https://developers.notion.com/reference/errors

我沒有正確構建 object,這就是我收到此錯誤的原因。

rich_text_object的正確構造是愚蠢的:

properties: {
  "Excerpt": {
    "rich_text": [
      {
        "type": "text",
        "text": {
          "content": "hello"
        }
      }
    ]
  }
}

您可以在此處找到更多信息: https://developers.notion.com/docs/working-with-page-content#creating-a-page-with-content

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM