Search code examples
microsoft-graph-apimicrosoft-graph-mail

mail address contains # in odata filter making it invalid


I'm trying to get user incoming messages (emails) by calling list messages endpoint and filter out the mails he sent.

The problem is that the user mail address starts with # (i.e. the mail is something like #[email protected]) and so when sending the request to the full url:

url = "https://graph.microsoft.com/v1.0/Users/{user_id}/messages?$filter=sender/emailAddress/address ne '#[email protected]'"

I'm getting back a 400 (bad request) status code saying "Invalid filter clause"

If I remove the # then the request works (getting back 200) but then I might get mails where the sender is the user itself (i.e. #[email protected]).

Is there a workaround using GRAPH API? (I'm aware of the possibility to filter mails by myself after getting response.. that's not what I'm looking for..)

Thanks


Solution

  • I think I found the solution - to add ' before the special character (in my case, #) so if I change the filter to be .. ne ''#[email protected]' then it seems to work fine.