Search code examples
microsoft-graph-apionedrive

Filtering on recent files Microsoft Graph API not working


I am trying to fetch recently accessed items for a user using this endpoint. While fetching the items themselves works, I am unable to filter on lastModifiedDateTime, which is a property of the API response, as per this link.

I am making a GET request to the following endpoint:

https://graph.microsoft.com/v1.0/me/drive/recent?$filter=lastModifiedDateTime ge 2020-08-25T05:30:00Z

And I am getting a Microsoft.SharePoint.Client.InvalidClientQueryException with the following message:

'The expression "lastModifiedDateTime ge 2020-08-25T05:30:00Z" is not valid.'

Please help!


Solution

  • The error which is showing up says 'The expression "lastModifiedDateTime ge 2020-08-25T05:30:00Z" is not valid' which means the expression which you have given in the filter is not right. You need to correct it as shown below.

    https://graph.microsoft.com/v1.0/me/drive/recent?$filter=lastModifiedDateTime ge '2020-08-25T05:30:00Z'
    

    But still this call doen't work because the filter is not supported on this property and you will end up 'Invalid filter clause'.

    As a work around you can get the recent files and filter it on your end as most of the properties doesn't support filtering yet.