使用Graph API按Lookup列筛选SharePoint文档库项报错如何解决
解决方案
原请求返回
Operation not supported错误,是因为Microsoft Graph API的drives端点暂不支持对listitem/fields这类嵌套扩展属性执行$filter过滤操作,需要切换到SharePoint列表原生端点实现该需求。
步骤1:获取文档库对应的关联信息
首先调用两个接口拿到后续需要的参数:
- 获取文档库对应的SharePoint列表ID:
返回结果中的https://graph.microsoft.com/v1.0/drives/{drive_id}/listid字段即为文档库对应列表ID,记为{list_id}。 - 获取文档库所属的SharePoint站点ID:
返回结果中的https://graph.microsoft.com/v1.0/drives/{drive_id}/siteid字段即为站点ID,记为{site_id}。
步骤2:使用列表端点执行查找列过滤
切换到站点列表的items端点发起查询,该端点原生支持对fields内自定义字段的过滤,同时可以扩展返回对应的driveItem文档属性:
https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items?$expand=driveItem&$filter=fields/CustomRecordLookupId eq 1
特殊场景适配
如果你的CustomRecordLookupId是多值查找列,需要调整过滤语法为:
https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items?$expand=driveItem&$filter=fields/CustomRecordLookupId/any(l: l eq 1)
查询结果说明
返回结果中driveItem节点包含和drives端点查询一致的所有文档属性,包括文件名称、下载地址、修改时间、路径等,可直接使用。
内容的提问来源于stack exchange,提问作者anjuna47
相关产品推荐
相关产品推荐

