Drive files from Sharepoint online site by using filter issue

Huiyan Zhao (Chinasoft) 21 Reputation points
2022-01-26T05:37:00.41+00:00

Hi All,

Does anyone know this error, I am trying to use Filter method, do we have plan to support Filter for sites, like Name and Modified date?

var list = graphServiceClient.Sites[site.Id].Lists.Request().Filter("Name gt 'Milk'").GetAsync().GetAwaiter().GetResult();
168498-1234567.png

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,663 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. CarlZhao-MSFT 37,216 Reputation points
    2022-01-26T07:33:35.837+00:00

    Hi @Huiyan Zhao (Chinasoft)

    This is a known issue, the /sites/{site id}/lists endpoint does not currently support $filter. You can submit User Voice to add support for the filter and I'll vote for you.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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 comments No comments

  2. JanardhanaVedham-MSFT 3,536 Reputation points
    2022-01-26T09:48:51.503+00:00

    Hi @Huiyan Zhao (Chinasoft) ,

    Please find my findings on applying the filters using the below Microsoft Graph SharePoint APIs.

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

    Filter is working fine for 'displayName' list field at SharePoint lists level as shown below but currently filter is not supported for other list fields such as "Name", "lastModifiedDateTime', "createdDateTime',webUrl...etc.

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists?$filter=displayName eq 'Documents'  
    

    Eample :

    GET https://graph.microsoft.com/v1.0/sites/77978070-f1b8-40c8-9f79-0109712343/lists?$filter=displayName eq 'Documents'

    168692-image.png

    Incase you would like to filter the files/documents or list items within a document library or a list then below Microsoft Graph SharePoint API can be used.

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

    Below are few example cases of applying filter on files/documents of a SharePoint Document Library :

    Note : Please note that Prefer: HonorNonIndexedQueriesWarningMayFailRandomly should be added in the request header when applying the fiter using Field 'ContentType'

    Filter the files by Document Name in a document library :

    Example :

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=fields&$filter=fields/ContentType eq 'Document' and fields/FileLeafRef eq  'File Name'  
    

    168666-image.png

    Filter the files by Modified Date in a document library :

    Example :

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=fields&$filter=fields/ContentType eq 'Document' and fields/Modified ge 'DateTime'  
    

    168647-image.png

    Filter the files by Document Title in a document library :

    Example :

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=fields&$filter=fields/ContentType eq 'Document' and fields/Title eq  'Document Title'  
    

    Moreorver you can also leverage Microsoft Graph Files/Drives API for fetching & filtering the files from SharePoint Document libraries/drives.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments