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

标签 sharepoint microsoft-graph-api

我正在尝试通过 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/

相关文章:

sharepoint - 以编程方式将 SharePoint 工作流添加到列表

c# - Sharepoint Web 部件中的多行文本框

sharepoint - 如何为 SharePoint 事件接​​收器设置过滤器?

azure-active-directory - AAD 应用遇到 AADSTS50000 提示=admin_consent

android - Microsoft Graph API DateTimeZone 日期格式

sharepoint - 在文档库之外创建 SharePoint 网页

sharepoint - 以编程方式更新 Sharepoint 中的文档库

microsoft-graph-api - 使用Microsoft Graph API更新PasswordProfile(密码重置)

c# - 使用 Microsoft Graph API 获取 Outlook 中的所有消息

c# - 如何使用 Microsoft Graph api 从 azure Active Directory 获取所有用户属性