Graph API cannot use $search

Blue Tongue 1 Reputation point
2022-04-04T11:44:21.92+00:00

Hello all,

Graph API newbie here.

I am trying to search for messages in the body of the email.
I have tried the following and it did not work because it appears that filter cannot filter body of the email.

$upn = '******@domain.com'  
$api = "https://graph.microsoft.com/v1.0/users/$upn/messages?filter=contains(subject,'XYZ') or contains(body/content,'XYZ')&count=true"  
$api = "https://graph.microsoft.com/v1.0/users/$upn/messages?filter=contains(bodyPreview,'XYZ')&count=true"  

So, I moved to use $search like below which just return all messages in the mailbox.

$api = "https://graph.microsoft.com/V1.0/users/$upn/messages?$search=subject:'XYZ'&count=true"  
$api = "https://graph.microsoft.com/V1.0/users/$upn/messages?$search=bodyPreview:'XYZ'&count=true"  

What did I do wrong?

Community Center | Not monitored
0 comments No comments

3 answers

Sort by: Newest
  1. Blue Tongue 1 Reputation point
    2022-06-22T01:46:41.127+00:00

    I finally got the answer after posting on Spiceworks and Serverfault.

    The issue has to do with variable substitution.

    Please check here.
    https://community.spiceworks.com/topic/2353956-graph-api-to-filter-bodypreview-or-body-content-in-messages?page=1#entry-9487618
    https://serverfault.com/questions/1103528/graph-api-cannot-use-search

    Was this answer helpful?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  3. Sheena-MSFT 1,736 Reputation points
    2022-04-04T18:03:20.087+00:00

    Hi @Blue Tongue ,

    According to this documentation search-query-parameter , to search for messages in the body of an email use the following API https://graph.microsoft.com/v1.0/me/messages?$search="body:XYZ"&count=true. You can check the above document for more searchable email property.

    OR use this search-concept-messages API.

    Please find the screenshot below:

    189804-search.png

    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.

    Was this answer helpful?


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.