Microsoft Graph API cannot filter /users by companyName?

Brian McCullough 1 Reputation point
2021-02-19T12:53:03.22+00:00

Microsoft Graph API cannot filter /users by companyName? For example, say Microsoft used the companyName attribute to distinguish between some of it's various Business Units (e.g. "Azure", "M365", "Windows", "XBox", "Surface" etc) and I wanted to return all users from "M365", I couldn't do that? I can do it when I ask for counts, but not when I ask for a collection of users. For example:

Getting a count works (as long as I provide the consistencylevel = eventual HTTP Request Header):
https://graph.microsoft.com/v1.0/users/$count?$filter=userType ne 'guest' and accountEnabled eq true and companyName eq 'XBox'

https://graph.microsoft.com/v1.0/users?$filter=accountEnabled eq true and companyName eq ‘XBox’

{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'.",
"innerError": {
"date": "2021-02-19T12:36:03",
"request-id": "356e002c-6fb3-4f36-b269-92348cfc1043",
"client-request-id": "60ae7f54-b3c4-ea55-1dba-bc6ac1a10b54"
}
}

Microsoft Graph Users API
Microsoft Graph Users API
A Microsoft API that allows you to build compelling app experiences based on users, their relationships with other users and groups, and the resources they access for example their mails, calendars, files, administrative roles, group memberships.
737 questions
Microsoft Graph Azure AD API
Microsoft Graph Azure AD API
A Microsoft API that queries the user's profile, finds other users, manages organizational relationships, tracks assignments, or creates original solutions that incorporate existing organizational data.
257 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Dan Kershaw 416 Reputation points Microsoft Employee
    2021-03-05T19:00:57.35+00:00

    @Brian McCullough There's a bug in your query. You need to put the $count in the query parameters. When I do that, the query works for me.

    GET https://graph.microsoft.com/v1.0/users?$count=true&$filter=userType ne 'guest' and accountEnabled eq true and companyName eq 'XBox'

    Hope this helps
    Dan.

    0 comments No comments