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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,569 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,686 Reputation points Microsoft Vendor
    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.