gpt4 book ai didi

sharepoint - 如何在 Microsoft Graph 中按创建者筛选 SharePoint 列表项?

转载 作者:行者123 更新时间:2023-12-03 11:19:59 34 4
gpt4 key购买 nike

我正在尝试通过 Microsoft Graph 从 SharePoint 获取列表项的集合,我想按 CreatedBy 对其进行筛选。请求:https://graph.microsoft.com/v1.0/sites/{siteid}/lists/TeamRequests/items

返回:

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('{url}')/lists('TeamRequests')/items",
"value": [
{
"@odata.etag": "\"56ad787e-bd69-464a-b5da-dd953e40d7c4,13\"",
"createdDateTime": "2018-02-26T08:34:26Z",
"eTag": "\"56ad787e-bd69-464a-b5da-dd953e40d7c4,13\"",
"id": "11",
"lastModifiedDateTime": "2018-03-22T13:20:03Z",
"webUrl": "{url}/Lists/TeamRequests/11_.000",
"createdBy": {
"user": {
"email": "{email}",
"id": "9c9cbb67-c049-4a2d-845d-6c5ca2300041",
"displayName": "{Name}"
}
},
"lastModifiedBy": {
"user": {
"email": "{email}",
"id": "9c9cbb67-c049-4a2d-845d-6c5ca2300041",
"displayName": "{Name}"
}
},
"parentReference": {},
"contentType": {
"id": "0x01005F15F8133495554D834FF82F187AD0630002133A9CCDE4494D8CB2206D7D6453D6"
}
},

现在我想针对 createdBy(Id、显示名称或电子邮件地址)过滤此请求。我尝试了 ?$filter=createdBy/user/email eq '{email}' 和对 id 或 displayName 的类似请求。他们都回来了

{
"error": {
"code": "generalException",
"message": "An unspecified error has occurred.",
"innerError": {
"request-id": "492e3bde-05fe-4484-a475-435ff0aa70b6",
"date": "2018-07-23T07:41:46"
}
}
}

那么如何完成这个过滤器呢?它甚至受支持吗?

最佳答案

尽管这听起来像是一个简单的查询,但我还没有想出比以下解决方案更简单的方法:

似乎不支持按用户字段过滤,除非提供了 user id ,这就是解决方案包含两个步骤的原因:

1) 首先,我们需要确定用户Id通过 Email ,为此可以使用以下查询:

https://graph.microsoft.com/v1.0/sites/root/lists('User Information List')/items?expand=fields(select=Id,Email)

*其中User Information List系统列表存储用户属性,包括 Id 和 Email 属性 *

2) 一旦用户Id已解决,可以应用按用户 id 过滤项目的最终查询:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists('list-name')/items?filter=fields/<user-field-name>LookupId eq '<user-id>'  

在哪里

<user-field-name>LookupIdCreated 的情况下,除了用户字段之外,还有一个字段被公开字段名称应为 AuthorLookupId

例子:

https://graph.microsoft.com/v1.0/sites/root/lists('TeamRequests')/items?filter=fields/AuthorLookupId eq '10'

注意

In some cases the following error is returned Field '' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists.

In that case the following request header needs to be applied:

Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

关于sharepoint - 如何在 Microsoft Graph 中按创建者筛选 SharePoint 列表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51473825/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com