How to query emails by recipient's email address?

Shaun Yang (Medalsoft) 0 Reputation points
2024-05-13T08:49:38.14+00:00

I am using the Graph REST API. Below is my URL.

https://graph.microsoft.com/v1.0/me/mailFolders('SentItems')/messages?$filter=sentDateTime ge 2024-04-27T16:00:00Z and sentDateTime le 2024-05-04T15:59:59Z and toRecipients/any(a:a/emailAddress/address eq '.@gmail.com')"

I got error ErrorInvalidUrlQueryFilter, the message is The query filter contains one or more invalid nodes.

How can I fix this or is there any other way to achieve my goal?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,776 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Saranya Madhu-MSFT 150 Reputation points Microsoft Vendor
    2024-05-13T17:26:36.3666667+00:00

    Hello @Shaun Yang (Medalsoft) ,

    Thanks for reaching Microsoft!

    I am able to replicate your issue. I would like to suggest a workaround. You can try using the $search query parameter with the Microsoft Graph API.

    For example, you can use the following query to filter by the "to" field:

    https://graph.microsoft.com/v1.0/me/mailFolders/SentItems/messages?$search="to:{searchphrase}"

    Document reference: https://learn.microsoft.com/en-us/graph/search-query-parameter?tabs=http

    Hope this helps.

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