'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…



Solution 1:[1]

Exploring in the notion.databases.update()type definition, there're types info about each params. And in checkbox property, I find these below:

declare type UpdateDatabaseBodyParameters = {
   | null | {
        checkbox: EmptyObject;
        type?: "checkbox";
        name?: string;
    } 
}

checkbox param should be EmptyObject. That's why the compiler shows the error I got, body.properties.Done.checkbox should be an object.

Then, I digged into EmptyObject type definition, and that's here:

declare type EmptyObject = Record<string, never>;

Record<key, value> is an object type definition that has types {key : value}.

Getting back to the issue, EmptyObject is an object that accepts {string: never}. And indeed, type never does not accept any types. Therefore I can set nothing inside the object as a property.

In conclusion, I couldn't find a way to mutate the checkbox property already being on the exixsed DB through API.

If someone know the appropriate way, please let me know...

Thx.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tori_san