In graph API, how to use $filter with or and eq?

Aravind Pai 0 Reputation points
2023-01-29T06:26:58.6233333+00:00

I want to use the Graph API to filter emails from either user1@example.com or user2@example.com.

Referring to the documentation at https://learn.microsoft.com/en-us/graph/filter-query-parameter, I created the following query:

https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=((from/emailAddress/address) eq 'user1@example.com') or ((from/emailAddress/address) eq 'user2@example.com')

However, this returns only email from user2@example.com. It appears that the query as I have written causes the or operator to not work as expected, and only consider the last operand.

How can I fix my query to make the or operator work properly?

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,761 Reputation points Microsoft External Staff
    2023-01-30T04:51:02.5133333+00:00

    Hello @Aravind Pai ,

    With or in Microsoft Graph API, I am able to get messages sent by 2 users.

    GET /me/mailFolders/Inbox/messages?$filter=(from/emailAddress/address eq 'email1@example.com' or from/emailAddress/address eq 'email2@example.com')
    

    Here is my test result, using the above Graph API $filter=(from/emailAddress/address eq 'email1@example.com' or from/emailAddress/address eq 'email2@example.com').

    Hope this helps.

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.