2

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 Answer 1

1

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}/"
    }
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Vadim, by this approach items/item-id i can't filter in complex scenarios such as where isactive=true and (id=9 or id=8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.