Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odata query for outlook rest api

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.

like image 640
seba_sencha Avatar asked May 24 '16 13:05

seba_sencha


People also ask

How do you call REST API in Outlook?

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.

What is OData query?

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.


1 Answers

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'))
like image 121
Roman Pletnev Avatar answered Sep 26 '22 07:09

Roman Pletnev