1

I am trying to get a list of emails given their InternetMessageID.

For one given InternetMessageID, I can retrieve the corresponding mail following the syntax provided in Outlook documentation

 "https://outlook.office365.com/api/beta/me/messages?$filter=SingleValueExtendedProperties/any(ep:  ep/PropertyId eq 'String 0x1035' and ep/Value eq '<12.FF.36768.EE3E3365@twitter.com>' )";

Now let us say that I want to retrieve two mails with the same request I did not manage to get a successful syntax.

For example

 "https://outlook.office365.com/api/beta/me/messages?$filter=SingleValueExtendedProperties/any(ep:  ep/PropertyId eq 'String 0x1035' and (ep/Value eq '<12.FF.36768.EE3E3365@twitter.com>' or ep/value eq 'anothermailid@toto.com'))";

does not work. A BadRequest is returned with a message

The filter expression for $filter does not match to a single extended property and a value restriction.

I have tried many combination of grouping and also test with an $expand statement as suggested in this question. Is there a way to perform such kind of requests with Outlook Web Api of Graph API ?

Community
  • 1
  • 1
Benoit Patra
  • 4,355
  • 5
  • 30
  • 53

1 Answers1

3

I just tried this as well, and I get a more informative error message:

{
  "error": {
    "code": "ErrorInvalidUrlQueryFilter",
    "message": "The filter expression for $filter on property ExtendedProperty only allows 
               [and] and [eq] operators. The equality can only be specified between 
               'PropertyId' and a constant or 'Value' and a constant (for example: 
               PropertyId eq 'value')."
  }
}

UPDATE: Checked with my engineering team, and this error refers to what is inside the ANY statement. You can't use OR in there. So to make this work, you need two separate ANY statements joined by an OR:

https://outlook.office.com/api/beta/me/messages?$filter=
  SingleValueExtendedProperties/any(ep: ep/PropertyId eq 'String 0x1035' 
                                    and ep/Value eq 'someid@somedomain') or 
  SingleValueExtendedProperties/any(ep: ep/PropertyId eq 'String 0x1035' 
                                    and ep/Value eq 'otherid@otherdomain')
Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • 1
    Thanks! I ended up using EWS instead of Office 365 apis (fortunately azureAD allows us to do so) . When this will be possible I would probably go back to use Office365 REST apis. – Benoit Patra Nov 30 '15 at 23:29
  • For information: it looks like that this type of request cannot hold more than 9 'Or' – Benoit Patra Dec 13 '15 at 15:27
  • Jason, is it possible to do the filter above (on just a single Message-ID) with the new Graph API? The same query doesn't seem to work, against graph.microsoft.com/v1.0/me/messages?$filter=... I see error code "BadRequest" and message "Invalid filter clause" – garrettm Jun 09 '20 at 23:03
  • @garrettm The new Graph API is pretty different from EWS & O365 api. You can chain clauses together using $filter like this: https://graph.microsoft.com/v1.0/users/myemail@someaddress.com/messages?$filter=Contains(Subject,'test')+or+Contains(Subject,'role') – Midiman Dec 07 '20 at 20:00