如何通过Microsoft Graph中的Created筛选SharePoint列表项?

扬尼克·里克曼斯

我正在尝试通过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,displayName或电子邮件地址)过滤此请求。我尝试了?$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"
        }
    }
}

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

瓦迪姆·格雷米亚切夫(Vadim Gremyachev)

即使听起来像是一个简单的查询,我还是没有想到比以下解决方案更简单的方法:

似乎除了提供用户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和电子邮件属性)的位置*

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>LookupId是除了用户字段之外正在暴露的字段,如果是Created字段,则名称应为AuthorLookupId

例:

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

注意

在某些情况下,返回以下错误。字段“”无法在过滤器或orderby中引用,因为未索引。提供“ Prefer:HonorNonIndexedQueriesWarningMayFailRandomly”标头以允许此操作,但请注意,此类查询可能在大型列表上失败。

在这种情况下,需要应用以下请求标头:

首选:HonorNonIndexedQueriesWarningMayFailRandomly

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Microsoft Graph SDK和SharePoint列表项

如何使用Microsoft Graph API创建SharePoint列表项?

使用Microsoft Graph API更新SharePoint列表项

如何更新 SharePoint 目录中的“列表项”

如何使用Microsoft Graph API中的筛选器获取SharePoint项目?

通过Microsoft Graph请求时,列表项为空

如何在 Power Automate 中通过查阅列从 SharePoint 列表中筛选查询

如何通过Microsoft Graph API在Sharepoint中为文档创建共享链接

如何在 SharePoint Online 中打印多个列表项

如何在选定的 SharePoint 列表项列中检索值

如何使用 REST API 在 SharePoint 中获取列表项?

如何在共享点列表项中添加状态“活动”或“非活动”。通过使用Sharepoint Designer?

Sharepoint Online列表项查询使用Microsoft Graph API返回空数组

如何使用Microsoft Graph API更新SharePoint列表中“人员”或“组”列的值?

如何同意通过 Microsoft Graph Webhook API 订阅?

Microsoft Graph:如何通过 Web 应用从组织用户获取数据?

如何通过 Microsoft Graph API 添加内嵌图像?

如何通过Microsoft Graph API检索itemAttachment的内容

如何通过Microsoft Graph API获取当前用户的Delve URL

如何通过 Microsoft Graph API 迭代 Sharepoint 站点的文档库项目?

如何使用Microsoft Graph API通过自定义列值查找SharePoint文档

如何通过Microsoft CRM中的Javascript访问实体视图

如何使用Graph API从SharePoint列表中临时删除项目

如何通过Microsoft Graph API / SDK将自适应卡发送给Microsoft团队?

如何使用Microsoft Graph API通过通讯组列表电子邮件过滤组?

如何在 Microsoft Graph API 中过滤 Sharepoint 术语?

Microsoft Graph Sharepoint子站点列表

如何通过列表中的值查询DynamoDB筛选

通过 microsoft graph 来宾用户列表