Getting body validation error when modifying Notion pages with JavaScript SDK

I keep running into this validation error when trying to update page properties in my Notion database using the JavaScript SDK.

The error message says:

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.'
}

Here’s what my code looks like:

async function modifyPages() {
  const response = await notion.databases.query({ database_id: `${dbId}` });

  response.results.forEach(async (item, idx) => {
    let prop_id = item.properties.Description.id;
    if (idx === 0) {
      try {
        const result = await notion.pages.update({
          page_id: item.id,
          properties: {
            [prop_id]: {
              type: "rich_text",
              rich_text: {
                "content": "hello world"
              }
            }
          }
        })

      } catch (error) {
        console.log(error.message)
      }
    }
  })
}
modifyPages();

I’m confused about where this body validation issue is coming from and how to fix it. Can anyone help me understand what’s wrong with my request structure?

The issue lies in your rich_text property structure. You need to wrap the rich_text content in an array and use a specific text object. Adjust your code by changing the current definition: javascript rich_text: { "content": "hello world" } to: ```javascript
rich_text: [
{
“text”: {
“content”: “hello world”
}
}
]

Your forEach loop with async/await is problematic and might be contributing to the validation issues. The forEach method doesn’t handle async operations properly, which can cause race conditions and malformed requests. Replace it with a regular for loop or for…of loop to ensure proper async execution. Also, double-check that your prop_id is actually resolving to a valid property identifier. I encountered similar body validation errors when the property ID was undefined or incorrectly referenced, which matches the error message you’re seeing about undefined values. Try logging the prop_id value before making the API call to verify it’s being set correctly from the database query response.

just hit this same bug last week! the problem is youre mixing up property references - when updating pages you should use the property name instead of the id in most cases. try replacing [prop_id] with just “Description” in your properties object. notion gets picky about this stuff and the validation errors are confusing af