Filter users on 'officeLocation' in Graph API

Viewed 2675

I'm working with the Microsoft Graph API and what I'm trying to achieve is to import all the people in my office location from Azure AD into my personal contacts.

Using the Graph Explorer I can find myself in /users/ using $filter - so using https://graph.microsoft.com/v1.0/users?$filter=mail eq '<MyEmailAddress>'. See the results below:

enter image description here

So this user (me) has a property officeLocation which is the propery I would like to filter on in order to get all my colleagues in the same office. Therefore I tried: https://graph.microsoft.com/v1.0/users?$filter=officeLocation eq '<MyOfficeLocation>'

However - I get a Request_UnsupportedQuery error:

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported or invalid query filter clause specified for property 'officeLocation' of resource 'User'.",
        "innerError": {
            "request-id": "407d5376-eeb4-46a5-8c93-c20e5b6b322e",
            "date": "2017-07-13T15:26:49"
        }
    }
}

Does this mean that I'm not allowed to filter on this property? That would be rather unfortunate. If so - any workarounds I can apply?

2 Answers

It works like this with $count, even including $expand and $select clauses:

GET https://graph.microsoft.com/v1.0/users?$top=999&$count=true&$filter=startswith(officeLocation,'EU_')&$select=id,displayName&$expand=manager($select=id,mail,displayName;$levels=1)
ConsistencyLevel: eventual

Here, I'm querying users' id, displayName and some details of their 1st level manager (id, mail, displayName) where the user's officeLocation starts with 'EU_'

And you must send ConsistencyLevel: eventual in the request header for it to work..

graph api screenshot

Related