Notion JS SDK: Encountering validation issues when modifying page content

Help! I’m stuck with a weird error in Notion’s JavaScript SDK.

I’m trying to update some pages in my Notion database, but I keep getting this validation 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.'
}

I’ve been scratching my head over this for hours. Here’s a simplified version of what I’m trying to do:

async function changePageStuff() {
  const dbResults = await notionClient.databases.query({ database_id: 'my-db-id' });

  dbResults.results.forEach(async (page, idx) => {
    if (idx === 0) {
      try {
        await notionClient.pages.update({
          page_id: page.id,
          properties: {
            [page.properties.Summary.id]: {
              type: 'rich_text',
              rich_text: { content: 'New summary text' }
            }
          }
        });
      } catch (oops) {
        console.log(oops.message);
      }
    }
  });
}

changePageStuff();

Anyone know why I’m getting this body validation error? I can’t figure out where it’s coming from. Any tips would be super helpful!

hey, ive had a similar hiccup. try logging page.properties to spot the correct prop. once you see a rich_text prop, update using that key. hope it fixes it, good luck!

I’ve encountered this issue before, and it’s often related to how the Notion API handles property updates. The error suggests you’re trying to update a ‘body’ property that doesn’t exist or isn’t configured correctly.

To resolve this, try fetching the page details first using notionClient.pages.retrieve(), then use that to construct your update payload. This ensures you’re working with the correct property structure:

const pageDetails = await notionClient.pages.retrieve({ page_id: page.id });
const summaryProperty = Object.values(pageDetails.properties).find(prop => prop.type === 'rich_text');

if (summaryProperty) {
  await notionClient.pages.update({
    page_id: page.id,
    properties: {
      [summaryProperty.id]: {
        rich_text: [{ type: 'text', text: { content: 'New summary text' } }]
      }
    }
  });
}

This approach should bypass the validation error by using the correct property ID and structure.

I’ve run into similar issues with the Notion API before, and it can be pretty frustrating. From what I can see in your code, the problem might be related to how you’re constructing the properties object in your update call.

When updating a page, you need to match the structure of the existing properties. The error message suggests that the API is expecting a ‘body’ property with specific fields (id, name, start), but you’re not providing those.

Try modifying your update call like this:

await notionClient.pages.update({
  page_id: page.id,
  properties: {
    Summary: {
      rich_text: [{ type: 'text', text: { content: 'New summary text' } }]
    }
  }
});

This assumes ‘Summary’ is the actual name of the property in your Notion database. Also, make sure you’re using the latest version of the Notion SDK, as older versions might have different property structures.

If this doesn’t solve it, you might want to log the full structure of ‘page.properties’ to see exactly what properties your page has, and match that structure in your update call. Hope this helps!