2
votes

How to filter SharePoint list-items by Id.

Id is out-of-the-box field in the SharePoint-list.

I am testing using graph-explorer: https://developer.microsoft.com/en-us/graph/graph-explorer

I tried with these filters

Working filter with Title:

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

Non-working filter with 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

1 Answers

1
votes

A single ListItem resource could be addressed by Id like this (refer Get item endpoint for a more details):

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

where

  • site-id - identifier of Site resource
  • list-id - identifier of List resource
  • item-id - identifier of ListItem resource

To retrieve multiple items by ids, JSON batch endpoint could be utilized, for example:

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}/"
    }
  ]
}