Trouble with Filtering in MS Graph API Query for Messages

Jeff 0 Reputation points
2023-10-17T11:47:16.14+00:00

Hi everyone,

I am having difficulty in filtering messages based on the receivedDateTime field while querying the Microsoft Graph API. I am aiming to retrieve messages for a particular user, filtered by a specific date.

However, I keep encountering a 400 Bad Request error whenever I include the ?$filter=receivedDateTime ge {date} in the request URL.

Here's the exact URL format I've been trying:

https://graph.microsoft.com/v1.0/users/{user_id}/messages?$filter=receivedDateTime ge 2023-10-01T00:00:00

And the error I receive is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request</h2>
<hr><p>HTTP Error 400. The request is badly formed.</p>
</BODY></HTML>

I have tried various date formats and url encodings. I am able to execute other queries without the filter successfully, so I believe the rest of my request setup is correct.

Can anyone provide insight on the correct way to format this filter, or point me to where in the documentation this is explained?

Thank you for your assistance!

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

1 answer

Sort by: Most helpful
  1. Vasil Michev 96,436 Reputation points MVP
    2023-10-17T15:32:18.57+00:00

    You are not using the proper format for a receivedDateTime value. Try this:

    https://graph.microsoft.com/v1.0/users/{userId}/messages?$filter=receivedDateTime ge 2023-10-01T00:00:00z