https://graph.microsoft.com/v1.0/drives/{driveid}/items?$filter=name eq 'TEST' does not filter and returns all the files in that drive

Abhilasha Sharma 0 Reputation points
2025-05-09T11:07:23.34+00:00

I wanted to filter all the data in a drive based lastModifiedDateTime date range and name. I am trying to use the below mentioned endpoints but data is not getting filtered.

  1. https://graph.microsoft.com/v1.0/drives/{driveid}/items?$filter=name eq 'TEST' does not filter and returns all the files in that drive
  2. https://graph.microsoft.com/v1.0/drives/{driveid}/items?$filter=lastModifiedDateTime ge 2025-04-01T00:00:00Z and lastModifiedDateTime le 2025-04-30T23:59:59Z

Please suggest a solution where I can filter all the data in a library

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

1 answer

Sort by: Most helpful
  1. Pardha Saradhi Reddy Jaladi-MSFT 390 Reputation points Microsoft External Staff
    2025-05-09T21:39:23.5033333+00:00

    Hello Abhilasha Sharma

    Thank you for reaching out to Microsoft Support!!

    Based on your query, filtering items in a OneDrive or SharePoint drive using Microsoft Graph API requires the correct endpoint and supported filter parameters.

    The $filter query parameter is not supported for items under drives/{drive-id}/items. That’s why your filter is not working correctly.

    To filter files, you should query the /drive/root/search(q='query') endpoint for name-based searches or use /drive/root/children along with $filter for metadata-based filtering.

    Filtering by name:

    The $filter query does not work on the /items endpoint. Instead, use the search feature:

    https://graph.microsoft.com/v1.0/drives/{driveid}/root/search(q='TEST')
    This will return files containing "TEST" in their name.

    Note: Filtering by name using the search endpoint does work, but it has some limitations. The search(q='TEST') query will return items that contain "TEST" in their name, but it does not support exact matches or advanced filtering like $filter

    **
    Filtering by lastModifiedDateTime:**

    If you need to filter items by lastModifiedDateTime, use /drive/root/children with $filter:

    https://graph.microsoft.com/v1.0/drives/{driveid}/root/children?$filter=lastModifiedDateTime ge 2025-04-01T00:00:00Z and lastModifiedDateTime le 2025-04-30T23:59:59Z
    Alternatively, you may need to retrieve all items and filter the results on your client-side, as filtering on lastModifiedDateTime might not be directly supported.

    Hope this helps.

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.