Share via

How to query emails by recipient's email address?

Shaun Yang (Medalsoft) 5 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 Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Saranya Madhu-MSFT 2,375 Reputation points Microsoft External Staff
    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.


Your answer

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