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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 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