notion-api - 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
解决方案
嗯,那是虎头蛇尾的。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;
}
推荐阅读
- c# - 如何将 ItemTemplate 的 TextBox 文本正确绑定到 List 的字符串元素?
- json - 如何修复跨站脚本弱点(在 JSON 响应中持续存在并在 Json 响应中反映)
- flutter - 有没有办法在 Flutter 中使用谷歌地图创建可搜索区域(使用 google_maps_flutter)?
- regex - 检查字符串 bash 中是否存在 2 个子字符串
- c# - C# 从 C++ cfg 文件导入图像坐标
- python-3.x - 使用 Python 通过 Kerberos 身份验证连接到 HDFS
- c# - 如何使用从控制器保留的文本框值重定向回视图上的表单
- typescript - 在ngrx实体中请告诉我什么类型
处于实体状态 - mysql - 无法在本地实例 MySQL 中构建架构
- html - 在 django 服务器中运行时 html 模板的 css 问题