filter query on List Item endpoint in graph api

Tarun koshy 131 Reputation points
2020-11-02T14:09:18.84+00:00

Hi,

I was looking to filter the listitem end point and I need a couple of clarifications regarding it.

1) To filter using this endpoint, I understand that 'Prefer:HonorNonIndexedQueriesWarningMayFailRandomly" header needs to be added which could fail for large lists. I wanted to know if this is generally a reliable way to filter and if not, Is there is any other method to achieve it?

2) Using the above header I have tried to filter using the Graph explorer and I notice that the filter works for a certain fields and doesn't work for others.

The following works:
https://graph.microsoft.com/v1.0/sites/root/lists/d7689e2b-941a-4cd3-bb24-55cddee54294/items?expand=fields&$filter=fields/Title eq 'Contoso Home'
https://graph.microsoft.com/v1.0/sites/root/lists/d7689e2b-941a-4cd3-bb24-55cddee54294/items?expand=fields&$filter=fields/Modified ge '2017-09-01'

But these dont:
https://graph.microsoft.com/v1.0/sites/root/lists/d7689e2b-941a-4cd3-bb24-55cddee54294/items?expand=fields&$filter=fields/id eq 6
https://graph.microsoft.com/v1.0/sites/root/lists/d7689e2b-941a-4cd3-bb24-55cddee54294/items?expand=fields&$filter=lastModifiedDateTime lt '2017-09-04'

The last two fields(fields/id and lastModifiedDateTime) do exist in the response. So, I would like to know if there is a reference to the list of fields that can be filtered.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,565 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,569 questions
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-11-03T03:00:11.683+00:00

    My test result is the same as yours. So far, there is no document to clarify which fields do not supported $filter.
    If you want to get an item with specified ID,you could use this endpoint:

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

    As a workaround,you could use the $filter keyword of SharePoint Rest Api to get the results you want.
    Demo: /_api/web/lists/GetByTitle('test')/items?$filter=Id eq 1


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful