Syntax error when using api into notion

Currently trying to send data to Notion. Following the Guide here -https://www.youtube.com/watch?v=ec5m6t77eYM Time stamp 1:55:23 ish.

Trying to learn how to use API’s and was recommended this video as it goes through most of the get commands. it’s actually mint learning this stuff just cannot for the life of me understand these errors yet. if anyone can tell me what I should look out for in future that would be great. thanks.

The error:

Sending data to Notion
@notionhq/client warn: request fail {
code: ‘validation_error’,
message: ‘body failed validation. Fix one:\n’ +
‘body.children[0].embed should be defined, instead was undefined.\n’ +
‘body.children[0].bookmark should be defined, instead was undefined.\n’ +
‘body.children[0].image should be defined, instead was undefined.\n’ +
‘body.children[0].video should be defined, instead was undefined.\n’ +
‘body.children[0].pdf should be defined, instead was undefined.\n’ +
‘body.children[0].file should be defined, instead was undefined.\n’ +
‘body.children[0].audio should be defined, instead was undefined.\n’ +
‘body.children[0].code should be defined, instead was undefined.\n’ +
‘body.children[0].equation should be defined, instead was undefined.\n’ +
‘body.children[0].divider should be defined, instead was undefined.\n’ +
‘body.children[0].breadcrumb should be defined, instead was undefined.\n’ +
‘body.children[0].table_of_contents should be defined, instead was undefined.\n’ +
‘body.children[0].link_to_page should be defined, instead was undefined.\n’ +
‘body.children[0].table_row should be defined, instead was undefined.\n’ +
‘body.children[0].ai_block should be defined, instead was undefined.\n’ +
‘body.children[0].table should be defined, instead was undefined.\n’ +
‘body.children[0].column_list should be defined, instead was undefined.\n’ +
‘body.children[0].column should be defined, instead was undefined.\n’ +
‘body.children[0].heading_1 should be defined, instead was undefined.\n’ +
‘body.children[0].heading_2 should be defined, instead was undefined.\n’ +
‘body.children[0].heading_3 should be defined, instead was undefined.\n’ +
‘body.children[0].paragraph should be defined, instead was undefined.\n’ +
‘body.children[0].bulleted_list_item should be defined, instead was undefined.\n’ +
‘body.children[0].numbered_list_item should be defined, instead was undefined.\n’ +
‘body.children[0].quote should be defined, instead was undefined.\n’ +
‘body.children[0].to_do should be defined, instead was undefined.\n’ +
‘body.children[0].toggle should be defined, instead was undefined.\n’ +
‘body.children[0].template should be defined, instead was undefined.\n’ +
‘body.children[0].callout should be defined, instead was undefined.\n’ +
‘body.children[0].synced_block should be defined, instead was undefined.’
}
(node:10860) UnhandledPromiseRejectionWarning: APIResponseError: body failed validation. Fix one:
body.children[0].embed should be defined, instead was undefined.
body.children[0].bookmark should be defined, instead was undefined.
body.children[0].image should be defined, instead was undefined.
body.children[0].video should be defined, instead was undefined.
body.children[0].pdf should be defined, instead was undefined.
body.children[0].file should be defined, instead was undefined.
body.children[0].audio should be defined, instead was undefined.
body.children[0].code should be defined, instead was undefined.
body.children[0].equation should be defined, instead was undefined.
body.children[0].divider should be defined, instead was undefined.
body.children[0].breadcrumb should be defined, instead was undefined.
body.children[0].table_of_contents should be defined, instead was undefined.
body.children[0].link_to_page should be defined, instead was undefined.
body.children[0].table_row should be defined, instead was undefined.
body.children[0].ai_block should be defined, instead was undefined.
body.children[0].table should be defined, instead was undefined.
body.children[0].column_list should be defined, instead was undefined.
body.children[0].column should be defined, instead was undefined.
body.children[0].heading_1 should be defined, instead was undefined.
body.children[0].heading_2 should be defined, instead was undefined.
body.children[0].heading_3 should be defined, instead was undefined.
body.children[0].paragraph should be defined, instead was undefined.
body.children[0].bulleted_list_item should be defined, instead was undefined.
body.children[0].numbered_list_item should be defined, instead was undefined.
body.children[0].quote should be defined, instead was undefined.
body.children[0].to_do should be defined, instead was undefined.
body.children[0].toggle should be defined, instead was undefined.
body.children[0].template should be defined, instead was undefined.
body.children[0].callout should be defined, instead was undefined.
body.children[0].synced_block should be defined, instead was undefined.
at buildRequestError (/rbd/pnpm-volume/1ae46c8e-7572-4360-8bc6-f5c7840689da/node_modules/@notionhq/client/build/src/errors.js:162:16)
at Client.request (/rbd/pnpm-volume/1ae46c8e-7572-4360-8bc6-f5c7840689da/node_modules/@notionhq/client/build/src/Client.js:378:54)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async createNotionPage (/app/index.js:125:22)
(Use node --trace-warnings ... to show where the warning was created)
(node:10860) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line API | Node.js v21.7.1 Documentation). (rejection id: 1)
(node:10860) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I don’t see where I have gone wrong. I understand the error to some extent and how it says stuff is undefined. But I do not see where this is the case. Before I added this last line of code in for the flavor text it worked perfectly and sending the data into Notion. don’t know where i went wrong. thanks in advance for any assistance.

Link to project - Glitch :・゚✧

It appears that you need to define all of those variables, but I don’t use notion or node.js! Sorry!

Yea I looked into it but am going code blind as I cannot seem to understand where I am going wrong in my js code!

Hi @Dylan_James - can you share how the app is supposed to work and what do you do to get to seeing those errors? I see that your code is in index.js but I’m not seeing that file referenced anywhere.

So the terminal runs node index.js which gets pokemon from an api and puts it into my notion database. It uses the .env file to know where to place these pokemon in my notion. I am following the guide - https://www.youtube.com/watch?v=ec5m6t77eYM . It is a weird project I know. but its good to understand most of how to use apis and integrate them into notion.

Simpler Representation:

PokeAPI > JavaScript > Notion

I hope this makes more sense @jenn!

body failed validation. Fix one:

body.children[0].quote should be defined, instead was undefined.

and yet here it is

const response = await notion.pages.create({
  ...
  "children": [
    {
      "object": "block",
      "type": "quote",
      "quote": {
        ...

weird. is body not the thing you pass into notion.pages.create? can you find some docs for this function and see if they have any specs on what to pass in or any examples

I found the issue…took me 2 days but it was mainly a spelling error with the qoute and then something about the content under children was not defined as i had no curly braces. I hope this coding stuff gets easier man…

1 Like

Hey hi, you need to check that the request body includes all the necessary properties as expected by the Notion API. Double-check the structure of the request body, including any required properties and their values. Make sure that you are passing valid data for each property expected by the Notion API.