Warm tip: This article is reproduced from serverfault.com, please click

mail address contains # in odata filter making it invalid

发布于 2021-01-19 09:08:33

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 #a@b.com) 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 '#a@b.com'"

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. #a@b.com).

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

Questioner
Noam
Viewed
0
Noam 2021-01-21 17:50:27

I think I found the solution - to add ' before the special character (in my case, #) so if I change the filter to be .. ne ''#a@b.com' then it seems to work fine.