Microsoft Graph: how to filter drive items by createdDateTime?

Anastasiia Ilina 20 Reputation points
2023-11-30T13:59:40.41+00:00

Hello! Is it possible to filter the drive items in a request to site/drive (Sharepoint) by createdDateTime? I tried this one:
GET https://graph.microsoft.com/v1.0/sites/{ourSiteId}/drive/root:/customFolder/children?$filter=createdDateTime le 2023-11-09T07:23:05.004Z

But got 400 'Invalid request'. The same was when I tried to change the date format to createdDateTime le 2023-11-09T07:23:05Z

When I call this endpoint without $filter=createdDateTime le 2023-11-09T07:23:05.004Z it works fine.

Is filtering by createdDateTime supported for drive items at all?

Thank you!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,379 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,248 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 39,906 Reputation points
    2023-12-01T08:35:32.2+00:00

    Hi @Anastasiia Ilina

    Filtering drive items based on the createdDateTime property is not currently supported, you can try getting a collection of child items and filtering locally.

    Using graph SDK:

    var items = await graphClient.Drives["{drive id}"].Items["{item id}"].Children.GetAsync();
    
    var date = DateTimeOffset.Parse("2023-10-20T08:27:26Z");
    
    foreach (var item in items.Value) {
    
        if (item.CreatedDateTime <= date) {
    
            Console.WriteLine("{" +  "id: " + item.Id + "\r\n" + "createdDateTime: " + item.CreatedDateTime + "}" + "\r\n");
        
        }
    }
    

    User's image

    Hope this helps.

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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful