Reputation: 109
I'm trying to return emails from Office 365 where the sender's email matches my query string. I tried $filter with contains but this threw an error stating I must use $search. The following works but doesn't restrict the scope of my search, i.e. to /Sender/EmailAddress/Name. Any ideas?
https://outlook.office365.com/api/v1.0/Me/Messages?$select=Subject,Sender,From&$search="Joe Bloggs"
Upvotes: 2
Views: 1742
Reputation: 27588
If you use a filtering method that is not supported, you will get an error message like the error you got .
In addition , When use $search query parameter without specifying a property ,the result will search the Body, Sender, and Subject properties. In your request , that will return all messages in the Inbox that contains your keyword in any of the three default properties.
The $search system query option restricts the result to include only those entities matching the specified search expression. You could click here for common fields by using the $search query parameter , if get all messages in the Inbox that were sent from a specific person is your requirement , you could try below query :
https://outlook.office.com/api/v2.0/me/messages?$search="from:[email protected]"
Above request also works in v1.0 , but return properties of the message are not the same (compare to v2.0) .
Upvotes: 3
Reputation: 2935
According to Resource reference for the Mail, Calendar, Contacts, and Task REST APIs, Office 365 REST API has its own Advanced Query Syntax for the $search
option. From that, it seems that you can restrict your search using the from:
qualifier.
GET https://outlook.office.com/api/v2.0/me/messages?$search="from:Joe Bloggs"
Note that the URI should be encoded (i.e., the double quotes and the space need to be percent encoded). Also, the examples are using v2.0 of the API. I'm not sure if this works with v1.0.
Upvotes: 0