最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Validation error while updating pages in notion by using the notion javascript SDK - Stack Overflow

programmeradmin2浏览0评论

Here's the error:

Client warn: request fail { code: 'validation_error', message: 'body failed validation. Fix one: body.properties.body.id should be defined, instead was undefined. body.properties.body.name should be defined, instead was undefined. body.properties.body.start should be defined, instead was undefined.' } body failed validation. Fix one: body.properties.body.id should be defined, instead was undefined. body.properties.body.name should be defined, instead was undefined. body.properties.body.start should be defined, instead was undefined

Here's my code :

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();

I am not getting why there is a body validation error and from where it originated. Any fixes?

Here's the error:

Client warn: request fail { code: 'validation_error', message: 'body failed validation. Fix one: body.properties.body.id should be defined, instead was undefined. body.properties.body.name should be defined, instead was undefined. body.properties.body.start should be defined, instead was undefined.' } body failed validation. Fix one: body.properties.body.id should be defined, instead was undefined. body.properties.body.name should be defined, instead was undefined. body.properties.body.start should be defined, instead was undefined

Here's my code :

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();

I am not getting why there is a body validation error and from where it originated. Any fixes?

Share Improve this question edited Jan 7, 2022 at 10:24 Murtuzaali Surti asked Jan 7, 2022 at 10:01 Murtuzaali SurtiMurtuzaali Surti 2711 gold badge2 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

After a little bit of digging, I found out that this error generally occurs when there are missing parameters in the request body. As per the official Notion documentation,

The request body does not match the schema for the expected parameters. Check the "message" property for more details. https://developers.notion./reference/errors

I did not construct the object correctly, and that's why I was getting this error.

The correct construction of rich_text_object is as follows:

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

You can find more information here : https://developers.notion./docs/working-with-page-content#creating-a-page-with-content

发布评论

评论列表(0)

  1. 暂无评论