skip to Main Content

I have come across an issue with the Graph API regarding the OData property filter while filtering files inside a SP Library.

The property, for some reason, does not filter at all, although it is required (calling without the filter property results in 400 BadRequest). I’ve first come across this issue on Dec 17th 2024, it still persists.

The steps I’ve managed to repro the issue with:

  • Create a new document library in a SP Site.
  • Create a few documents, ideally with the same extension. (In our case, document names are design.json, images.json, remoteEndpoints.json, questions.json.)
  • Create a query for Graph API and send it: https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items?$filter=name eq 'images.json'
  • Expected behavior: only images.json is returned.
  • Actual behavior: all 4 files are returned.

The issue still looks to be persistent with more files in the library. I’ve tested this issue on multiple tenants with the same outcome. The issue does not seem to be attributed to a specific client, as it comes up both in our PROD code (hosted as an Azure Function) and in Graph Explorer. The PROD code, where this issue came up, has been running since July 2024 without changes and without any problems.

I have tried looking into Graph API’s known issues, where there is a known issue thread regarding all OData queries, unfortunately, I could not find any mention of this issue.

Am I doing something wrong, or is there an issue in the service itself?

Thanks for all the advice!

2

Answers


  1. Filtering driveItems never didn’t work properly. I would recommend to use /v1.0/search/query endpoint for searching files

    POST https://graph.microsoft.com/v1.0/search/query
    
    {
        "requests": [
            {
                "entityTypes": [
                    "driveItem"
                ],
                "query": {
                    "queryString": "filename:images.json AND path:"https://contoso.sharepoint.com/sites/<site_name>""
                }
            }
        ]
    }
    

    with path in queryString you can reduce the searching to a specific site (document library or even to a specific folder)

    Login or Signup to reply.
  2. Suggested method by @user2250152, also works, but as you are trying with using $filter operation.

    I created one Document Library in my SharePoint environment and added some file into it like below:

    enter image description here

    While using the query which you provided, I got same response, below query list all the objects or files from that specific document library.

    GET https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items?$filter=name eq 'images.json'
    

    enter image description here

    Registered Microsoft Entra ID application and added and granted admin to consent to below API permission:

    enter image description here

    Generated Access token using client credentials flow with below parameters:

    GET https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token 
    client_id=<app_id>
    client_secret = <client_secret>
    grant_type = client_credentials
    scope= https://graph.microsoft.com/.default
    
    

    enter image description here

    To list the files from document library of SharePoint:

    GET https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/root/children?$filter=name eq 'images.json'
    

    Response:

    enter image description here

    Reference:

    List children of a driveItem

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search