首页 > 解决方案 > Notion API:有没有办法获取“人”属性中提到的用户的子页面数量?

问题描述

我正在尝试创建一些 Notion API 集成来帮助我的团队预测人员配备的可用性。

我正在编写一个函数,该函数应该使用过滤器类型people计算在数据库子页面的属性中提到特定用户的所有时间。people

这是我的代码:

async function getUserAssignmentCount(database, user) {
  const response = await notion.databases.query({
    database_id: database.id,
    filter: {
      "property": "People",
      "people": {
        "contains": user.id,
      },
    },
  });

  return Object.keys(response).length;
}

由于我不太明白的原因,这个函数只是4为每个用户返回。快速查看人员过滤器属性的 API 文档表明,您当前无法people使用过滤器过滤属性people……所以……idk??

任何人都可以想出一种方法来实现这一点,要么通过 API 中未记录的内容,要么通过一些从数据库people属性中获取所有用户 ID 的黑客方式?

谢谢 <3

标签: notion-api

解决方案


嗯,那是虎头蛇尾的。API 的文档仍然很差,但我找到了方法:

async function getUserAssignmentCount(database, user) {
  // Returns an object with keys `object`, `results`, `next_cursor`, `has_more`
  const response = await notion.databases.query({
    database_id: database.id,
    filter: {
      "property": "People",
      "people": {
        "contains": user.id,
      },
    },
  }); 
  
  // Returns the length of the filter results
  return response.results.length;
}

推荐阅读