Get Microsoft Graph messages by flagStatus using OData $filter

Viewed 452

I'm writing Microsoft Graph OData query to get mail messages based on message flagStatus in order to reuse working query in my C# code. How correct query should look like?

Following example is tried in Graph Explorer's sample account where all messages have object flag with field flagStatus = "notFlagged".

https://graph.microsoft.com/v1.0/me/messages?$filter=flag/flagStatus eq 'notFlagged'

It is expected that all messages should be returned. But as a result empty array was given back.

If in query I change eq to ne to be

https://graph.microsoft.com/v1.0/me/messages?$filter=flag/flagStatus ne 'notFlagged'

then all messages are returned. But by me it is expected that here should be empty array in this case.

Considering that maybe flag object isn't ready for filtering, I also tried to $expand it

https://graph.microsoft.com/v1.0/me/messages?$expand=flag&$filter=flag/flagStatus eq 'notFlagged'

but got error message

Property 'flag' on type 'microsoft.graph.message' is not a navigation property or complex property. Only navigation properties can be expanded.

So probably $expand for flag filtering is not needed. But is it possible to filter by message's flag at all?

Also if consider situation that flag object could be null and also flagStatus inside could be null (at least in C# class Microsoft.Graph.FollowupFlag property FlagStatus is nullable), then how query should look like to meet full requrirement below?

Get messages whose

  1. flag is null
  2. or flag/flagStatus is null
  3. or flag/flagStatus is 'notFlagged'
1 Answers

I had the same problem, probably is nullable as suggested. There's only three possible statuses according to the followupFlag documentation, so I worked around it with a not equal and condition for the two other statuses, complete and flagged.

https://graph.microsoft.com/v1.0/me/messages?$filter=flag/flagStatus ne 'flagged' and flag/flagStatus ne 'complete'
Related