How to use search and filter in the same query?
String url = "https://outlook.office.com/api/v2.0/me/messages?$filter=ReceivedDateTime ge 2016-02-22&$select=Subject,From,Body,ReceivedDateTime&$search=\"subject:(Chris Brown OR Michael Jackson)\"";
I need to find all mails with Subject
having either "Chris Brown" or "Michael Jackson" and mail received date after 22nd Feb, 2016. Also it should have Subject
, From
, Body
, ReceivedDateTime
in the REST response.
Could anyone please help?
FYI - I am getting output if it has either filter
or search
. But when given together, I am getting a "Bad Request" error.
In order to call the Mail API, the app requires an access token from the Microsoft identity platform. Use one of the supported OAuth 2.0 flows to obtain an access token.
The Open Data Protocol (OData) is a data access protocol built on core protocols like HTTP and commonly accepted methodologies like REST for the web. There are various kinds of libraries and tools can be used to consume OData services.
Right now this is not supported. From Use OData query parameters:
You cannot use $filter or $orderby in a search request.
So, the only way to do this is to perform a search via a query, and then filter on the client; or vice versa.
Update
In this particular case, since subject is filtrable and supposedly you only need an exact subject match (and not 'contains' for example), you can use something along the lines of:
https://outlook.office.com/api/v2.0/me/messages?$filter=(ReceivedDateTime ge 2016-02-22) and ((subject eq 'Chris Brown') or (subject eq 'Michael Jackson'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With