I need to retrieve all the user who has emails in different locations. The email could be in
{
...
mail: "[email protected]",
...
}
or
{
...
otherMails: ["[email protected]"],
...
}
I tried the url like
https://graph.windows.net/mytenant.onmicrosoft.com/users?api-version=1.6&$filter=mail eq '[email protected]' or any(otherMails: mail eq '[email protected]')
but its giving error:
"value": "')' or ',' expected at position 48 in 'mail eq '[email protected]' or any(otherMails: mail eq '[email protected]')'."
In my case, I ran below MS Graph query in Graph Explorer and got same error like this:
GET https://graph.microsoft.com/v1.0/users?&$filter=mail eq '[email protected]' or any(otherMails: mail eq '[email protected]')
Response:
To resolve the error, I ran below modified query and got the results successfully as below:
GET https://graph.microsoft.com/v1.0/users?$filter=mail eq '[email protected]' or otherMails/any(mail: mail eq '[email protected]')
Response:
In your case, the error occurred as you are using incorrect syntax in your query. To resolve it, make use of below modified query:
GET https://graph.windows.net/mytenant.onmicrosoft.com/users?api-version=1.6&$filter=mail eq '[email protected]' or otherMails/any(mail: mail eq '[email protected]')
Reference: Query and Paging Filters Options with Azure AD Graph API Supported | Microsoft