如何使用Microsoft Graph Api按ID筛选SharePoint列表项

时间:2019-05-01 00:30:09

标签: microsoft-graph

如何按ID筛选SharePoint列表项。

Id是SharePoint列表中的现成字段。

我正在使用graph-explorer测试:https://developer.microsoft.com/en-us/graph/graph-explorer

我尝试过使用这些过滤器

具有标题的有效过滤器:

https://graph.microsoft.com/v1.0/sites/root/lists/ba0dc64a-263c-44b6-8160-66a3034a1429/items?$ expand = fields&$ filter = fields /标题eq'1'

具有ID的无效过滤器:

https://graph.microsoft.com/v1.0/sites/root/lists/ba0dc64a-263c-44b6-8160-66a3034a1429/items?$ expand = fields&$ filter = fields / id eq'1'

{
    "error": {
        "code": "invalidRequest",
        "message": "A provided field name is not recognized",
        "innerError": {
            "request-id": "9f0bd335-bf60-42dd-893e-397fe62bc890",
            "date": "2019-05-01T00:25:51"
        }
    }
}

https://graph.microsoft.com/v1.0/sites/root/lists/ba0dc64a-263c-44b6-8160-66a3034a1429/items?$ expand = fields&$ filter = fields / Id eq 1

{
    "error": {
        "code": "BadRequest",
        "message": "Invalid filter clause",
        "innerError": {
            "request-id": "730490af-6b08-4ac1-8259-fa9bb9dd9e46",
            "date": "2019-05-01T00:26:28"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

单个{em> ListItem资源可以通过Id来寻址(有关更多详细信息,请参考Get item端点):

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}?$expand=fields

其中

  • site-id-Site资源的标识符
  • list-id-List资源的标识符
  • item-id-ListItem资源的标识符

要通过ID检索多个项目,可以使用JSON batch endpoint,例如:

POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
Body:  

{
  "requests": [
    {
      "id": "1",
      "method": "GET",
      "url": "/sites/root/lists/{list-id}/items/{item_id-1}/"
    },
    {
      "id": "2",
      "method": "GET",
      "url": "/sites/root/lists/{list-id}/items/{item_id-2}/"
    }
  ]
}