node.jsnotion-api

Notion API - set url or number property as blank or empty


I'm executing this query:

import { Client } from '@notionhq/client'
import https from 'https'

const auth = process.env.NOTION_TOKEN

const notion = new Client({
  auth,
  agent: new https.Agent({ keepAlive: true })
})

notion.pages.update({
  parent: { database_id: databaseId },
  page_id: 'xyz',
  properties: {
    NPM: { url: '' }, // want to update this field to empty value
    Downloads: { number: '' }, // want to update this field to empty value
    Size: { number: '' } // want to update this field to empty value
  }
})

But I get a validation error:

@notionhq/client warn: request fail {
  code: 'validation_error',
  message: 'body failed validation. Fix one:\n' +
    'body.properties.NPM.title should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.rich_text should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.number should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.url should be populated or `null`, instead was `""`.\n' +
    'body.properties.NPM.select should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.multi_select should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.people should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.email should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.phone_number should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.date should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.checkbox should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.relation should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.files should be defined, instead was `undefined`.\n' +
    'body.properties.NPM.status should be defined, instead was `undefined`.'
}

The Notion API doc says:

Email property value objects contain a string within the email property

But how can I set it as blank?

I tried undefined and null as well, but I got the same error.


Solution

  • The code I wrote in the question was good. Setting a property to null set is as blank - I had a typo on my production code.

    notion.pages.update({
      parent: { database_id: databaseId },
      page_id: 'xyz',
      properties: {
        NPM: { url: null },
        Downloads: { number: null },
        Size: { number: null }
      }
    })