Support filtering messages by body content

Andrew Omondi 246 Reputation points Microsoft Employee
2021-07-30T06:53:07.577+00:00

I've constructed the query below on Graph Explorer and got no messages in reply. My query.

https://graph.microsoft.com/v1.0/me/mailFolders('Inbox')/messages?$filter=subject eq '*****' and contains(body/content, '****')&$top=10

Do I understand correctly that a construct like 'contains(body/content, '****')' verifies that the body contains the object I specified? And the whole body of the object shouldn't just consist of it?

Sourced from https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1079

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

Accepted answer
  1. Danstan Onyango 3,741 Reputation points Microsoft Employee
    2021-08-02T10:27:18.26+00:00

    I don't think the body.content field is supported as filter item. In your case I think you may be better off with a search.

    Try Search with filters and see if it gives what you are looking for.

    POST https://graph.microsoft.com/v1.0/search/query  
    {  
        "requests": [  
            {  
                "entityTypes": [  
                    "message"  
                ],  
                "query": {  
                    "queryString": "subject:'Lunch' AND somestring-that-will-match-content"  
                }  
            }  
        ]  
    }  
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Keshav Kishore 1 Reputation point
    2022-02-10T03:32:20.443+00:00

    @Anonymous The response for more than one query fails to give the output.

    Request Json:

    {  
        "requests": [  
            {  
                "entityTypes": [  
                    "event"  
                ],  
                "query": {  
                    "queryString": "subject: 'check' AND (summary: 'nznzz')"  
                },  
            }  
        ]  
    }  
    

    Request response:

    {  
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)",  
        "value": [  
            {  
                "searchTerms": [  
                    "check",  
                    "summary",  
                    "nznzz"  
                ],  
                "hitsContainers": [  
                    {  
                        "total": 0,  
                        "moreResultsAvailable": false  
                    }  
                ]  
            }  
        ]  
    }  
    

    Request paylod:

    {  
        "requests": [  
            {  
                "entityTypes": [  
                    "event"  
                ],  
                "query": {  
                    "queryString": "subject: 'check'"  
                },  
            }  
        ]  
    }  
    

    Response: { "value": [ { "searchTerms": [ "check" ], "hitsContainers": [ { "total": 2, "moreResultsAvailable": false, "hits": [ { "summary": "nznzz", "subject": "check" } ]}

    0 comments No comments