Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing Notion API problem while trying updating databases properties: can't update checkbox

with Notion API and node.js, I'm trying to update database properties, especially the checkbox property, for my routine ToDo tasks checker.

But I couldn't find the correct way to do so. Error messages say my setting of the checkbox property isn't correct, but I couldn't find the right way in the Notion API documents.

Here's my code:

const { Client } = require("@notionhq/client");
require("dotenv").config();
const notion = new Client({ auth: process.env.NOTION_KEY });
const databaseId = process.env.NOTION_DATABASE_ID;

const uncheckRoutineTasksTodo = async () => {
    const response = await notion.databases.update({
        database_id: databaseId,
        icon:{//Worked
            type:"emoji",
            emoji:"💖"
        },
        properties: {
            Done: {
                checkbox: false,
            },
        },
    });
    console.log(response);
};
uncheckRoutineTasksTodo();

And error messages are:

@notionhq/client warn: request fail {
  code: 'validation_error',
  message: 'body failed validation. Fix one:\n' +
    'body.properties.Done.number should be defined, instead was `undefined`.\n' +
    'body.properties.Done.formula should be defined, instead was `undefined`.\n' +
    'body.properties.Done.select should be defined, instead was `undefined`.\n' +
    'body.properties.Done.multi_select should be defined, instead was `undefined`.\n' +
    'body.properties.Done.relation should be defined, instead was `undefined`.\n' +
    'body.properties.Done.rollup should be defined, instead was `undefined`.\n' +
    'body.properties.Done.title should be defined, instead was `undefined`.\n' +
    'body.properties.Done.rich_text should be defined, instead was `undefined`.\n' +
    'body.properties.Done.url should be defined, instead was `undefined`.\n' +
    'body.properties.Done.people should be defined, instead was `undefined`.\n' +
    'body.properties.Done.files should be defined, instead was `undefined`.\n' +
    'body.properties.Done.email should be defined, instead was `undefined`.\n' +
    'body.properties.Done.phone_number should be defined, instead was `undefined`.\n' +
    'body.properties.Done.date should be defined, instead was `undefined`.\n' +
    'body.properties.Done.checkbox should be an object, instead was `false`.\n' +
    'body.properties.Done.created_by should be defined, instead was `undefined`.\n' +
    'body.properties.Done.created_time should be defined, instead was `undefined`.\n' +
    'body.properties.Done.last_edited_by should be defined, instead was `undefined`.\n' +
    'body.properties.Done.last_edited_time should be defined, instead was `undefined`.\n' +
    'body.properties.Done.name should be defined, instead was `undefined`.'
}

As messages suggest, I tried to transform the checkbox property to object, but the result was the same.

properties: {
        Done: {
            checkbox: {
                checkbox:false
                }
           },
    },
body.properties.Done.checkbox should be an object, instead was `false`. 

Does someone know how to set checkbox property correctly? Please bail me out…

like image 825
tori_san Avatar asked Nov 15 '25 09:11

tori_san


1 Answers

You want to use notion.pages.update() instead notion.databases.update(). Each entry of a database is called a 'page', so you want to modify that, rather than the database itself.

As per the Notion API docs, an example would be:

const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });

(async () => {
  const pageId = {YOUR_PAGE_ID};
  const response = await notion.pages.update({
    page_id: pageId,
    properties: {
      'In stock': {
        checkbox: true,
      },
    },
  });
  console.log(response);
})();
like image 88
Lorenzo Sani Avatar answered Nov 17 '25 10:11

Lorenzo Sani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!