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
Filtering
driveItems
never didn’t work properly. I would recommend to use/v1.0/search/query
endpoint for searching fileswith
path
inqueryString
you can reduce the searching to a specific site (document library or even to a specific folder)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:
While using the query which you provided, I got same response, below query list all the objects or files from that specific document library.
Registered Microsoft Entra ID application and added and granted admin to consent to below API permission:
Generated Access token using client credentials flow with below parameters:
To list the files from document library of SharePoint:
Response:
Reference:
List children of a driveItem