Filtering multiple possible values with ExtendedPr

2019-02-21 01:25发布

问题:

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 ?

回答1:

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')