'Filter users by mobilePhone or businessPhones in Microsoft Graph

Is it possible to filter users by phone? I'm trying to find contacts in the global address list by their phone numbers.

I've tried https://graph.microsoft.com/v1.0/users?$filter=mobilePhone eq '+1234567890' but I get the following error: "code": "Request_UnsupportedQuery", "message": "Unsupported or invalid query filter clause specified for property 'mobilePhone' of resource 'User'."

also businessPhones/any does not seem to work. However, the above query works fine in personal contacts but then I would have to manually sync the global address list to my personal contacts which is not desirable.

Thanks in advance.



Solution 1:[1]

I know it's almost 4 years since the question being asked, as I'm also looking at the same question today, just going to leave the answer here for future wanderer.

According to this documentation https://docs.microsoft.com/en-us/graph/aad-advanced-queries, mobilePhone and businessPhones is consider an advanced queries, in order to query it, you need to have $count=true in the query string, and ConsistencyLevel: eventual in the header. And you might need to escape the + into %2B.

Microsoft announced this capability in 2020 https://developer.microsoft.com/en-us/office/blogs/microsoft-graph-advanced-queries-for-directory-objects-are-now-generally-available/.

Solution 2:[2]

You can do

https://graph.microsoft.com/v1.0/users?$filter=businessPhones/any(p:p le 'a') or mobilePhone ne null&$count=true

with headers ConsistencyLevel: eventual to get users with at least one businessPhone or a mobile.

the le 'a' compares the businessPhone string with the letter a, and since it's after +(123456789 in the alphabet, it'll return true for everything that's non empty

Solution 3:[3]

The various phone properties are supported in $filter.

I would recommending visiting the UserVoice and adding your suggestion (and voting up others).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen Saw
Solution 2 Aron Atilla Hegedus
Solution 3 Marc LaFleur