Microsoft 365 Graph API Testing And Troubleshooting

During office 365 activity if any error related to the filter mail is thrown, then refer the below steps as per the filter conditions.

As mentioned in Micrsoft Graph API - List Messages documentation :

When using $filter and $orderby in the same query to get messages, ensure to specify properties in the following format:

Below endpoints can be tested using the testing application available in the following link. (Sign-in with your account)

  1. Properties that appear in $orderby must also appear in $filter.

API Example :

GET https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$orderby=receivedDateTime DESC&$filter=receivedDateTime ge 2016-01-01T00:00:00Z and from/emailAddress/address eq 'o365mc@microsoft.com'&$select=receivedDateTime,from,subject,hasAttachments,bodyPreview

  1. Properties that appear in $orderby are in the same order as in $filter.

API Example :

GET https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$orderby=receivedDateTime DESC,from/emailAddress/address&$filter=receivedDateTime ge 2016-01-01T00:00:00Z and from/emailAddress/address eq 'o365mc@microsoft.com'&$select=receivedDateTime,from,subject,hasAttachments,bodyPreview

  1. Properties that are present in $orderby appear in $filter before any properties that aren't.

API Example :

GET https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$orderby=from/emailAddress/address&$filter=from/emailAddress/address eq 'o365mc@microsoft.com' and receivedDateTime ge 2016-01-01T00:00:00Z&$select=receivedDateTime,from,subject,hasAttachments,bodyPreview

  1. Below are the additional examples on "From", "Subject" properties and using $filter and $orderby DESC in the same query to get the messages :

API Examples :

Using From
GET https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id,receivedDateTime,subject,from&$orderBy=receivedDateTime DESC&$filter=receivedDateTime ge 2016-01-01T00:00:00Z and from/emailAddress/address eq 'o365mc@microsoft.com'

Using Subject
GET https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id,receivedDateTime,subject,from&$orderBy=receivedDateTime DESC&$filter=receivedDateTime ge 2016-01-01T00:00:00Z and from/emailAddress/address eq 'o365mc@microsoft.com' and subject eq 'Major update from Message center'

  1. A Workaround to filter the limitation is by using the extended property PidTagSenderSmtpAddress ​​​​​​( Refer documentation PidTagSenderSmtpAddress Canonical Property )
GET https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id,receivedDateTime,subject,from&$filter=singleValueExtendedProperties/any(ep:ep/id eq 'String 0x5D01' and ep/value eq 'gscales@blahblah.com')&$orderby=receivedDateTime DESC

** If the queries being used are static, then using SearchFolder will be a good approach (note this is how the favorites feature works in Outlook)

Refer below documentation for more information,