Graph API date filter issue.

Priya Khandre 1 Reputation point
2021-05-05T20:56:36.55+00:00

I was to fetch files only from a specific date eg. lastModifiedDateTime.
I am using the below API call to get all items from the drive: (all the driveItems are fetched in the response.)
https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children

response:

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives('{drive-id}')/root/children",
"@odata.nextLink": "https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children?$skiptoken={token}",
"value": [
{
"createdDateTime": "2021-04-22T14:55:50Z",
"eTag": "{tag}",
"id": "{id}",
"lastModifiedDateTime": "2021-04-22T14:55:50Z",
"name": "20",
"webUrl": "{webUrl}",
"cTag": "{tag}",
"size": 964153,
"createdBy": {
"user": {
"email": "{email-id}",
"id": "{id}",
"displayName": "XYZ"
}
},
"lastModifiedBy": {
"user": {
"email": "{email-id}",
"id": "{id}",
"displayName": "XYZ"
}
},
"parentReference": {
"driveId": "{drive-id}",
"driveType": "documentLibrary",
"id": "{parent-id}",
"path": "/drives/{drive-id}/root:"
},
"fileSystemInfo": {
"createdDateTime": "2021-04-22T14:55:50Z",
"lastModifiedDateTime": "2021-04-22T14:55:50Z"
},
"folder": {
"childCount": 3
}
} ]
}

I am using the below API to use filter on the above API call to get only files modified after '2021-04-22'
https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children?$filter=lastModifiedDateTime eq '2021-05-22'

response:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2021-05-05T20:49:26",
"request-id": "50ead21c-47fc-4b26-b36f-03d9be6e37fc",
"client-request-id": "50ead21c-47fc-4b26-b36f-03d9be6e37fc"
}
}
}

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

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 715 Reputation points Microsoft Vendor
    2024-02-17T13:53:41.28+00:00

    Hi Priya Khandre, Thanks for reaching out. I think its the issue related to Date format you should use the UTC time in following format

    $filter=lastModifiedDateTime eq 2016-02-26T14:41:09Z
    

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