Filter using Enum values in OData V4


To get all the products that are in Green color, we can send a request like:
“/svc/Products?$filter=PackageColor eq Namespace.Color’Green’”

Microsoft OData team - [Tutorial & Sample] Use Enumeration types in OData


After reading Brian Smith's blog post about using Planner to monitor/track changes to Office 365, I started investigating the Office 365 Service Communications API.

This API contains a lot of information, but this scenario requires only Message Center Updates. Since it is a REST endpoint, should be easy to filter, right? Turns out the MessageType property is an enum, so things are not that easy.

The exact question was posted on the MSDN forums. I answered the question, but I'm posting here for future reference.

If you look at the response to the Messages call, you should see an @odata.context property:
"@odata.context": "$metadata#Messages"

Make an authenticated call to that endpoint to get the metadata (schema). For the MessageType property, the type is specified as:

<Property Name="MessageType" Type="Microsoft.Office365ServiceComms.ExposedContracts.MessageType" Nullable="false" />

Further down in the document is the definition of this type:

<EnumType Name="MessageType" IsFlags="true">
  <Member Name="Unknown" Value="0" />
  <Member Name="Incident" Value="1" />
  <Member Name="PlannedMaintenance" Value="2" />
  <Member Name="MessageCenter" Value="4" />

Lastly, specifying an enum in OData filter requires that you include the "namespace" and then the enum value. So, to answer your question:{{tenant-id}}/ServiceComms/Messages?$filter=MessageType eq Microsoft.Office365ServiceComms.ExposedContracts.MessageType'MessageCenter'