You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Notion API将URL与Number类型属性设置为空值?

如何通过Notion API清空属性值?

我执行了以下代码尝试更新Notion页面属性,想把指定字段设为空值:

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: '' }, // 想要将此字段更新为空值
    Downloads: { number: '' }, // 想要将此字段更新为空值
    Size: { number: '' } // 想要将此字段更新为空值
  }
})

但触发了验证错误:

@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`.'
}

Notion API文档提到:

Email属性值对象在email属性中包含一个字符串

但我尝试过用undefined和null,还是出现相同错误,该怎么设置为空?


正确的清空方式

根据Notion API的校验规则,清空属性值需要对应传入null,绝对不能传空字符串'',同时要确保代码中指定的属性类型和数据库中定义的完全一致:

  • URL类型属性:{ url: null }
  • Number类型属性:{ number: null }

修改后的代码如下:

notion.pages.update({
  parent: { database_id: databaseId },
  page_id: 'xyz',
  properties: {
    NPM: { url: null }, // 正确清空URL属性
    Downloads: { number: null }, // 正确清空Number属性
    Size: { number: null } // 正确清空Number属性
  }
})

排查要点

如果传入null仍报错,检查这两点:

  • 确认数据库中目标属性的类型和代码中指定的类型完全匹配(比如NPM必须是URL类型,Downloads必须是Number类型)
  • 核对databaseId是否正确,确保目标页面属于该数据库

内容的提问来源于stack exchange,提问作者Manuel Spigolon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 18:52:35