question

BrianMcCullough-3684 avatar image
0 Votes"
BrianMcCullough-3684 asked ·

Microsoft Graph API cannot filter /users by companyName?

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-identitymicrosoft-graph-users
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Adding right tags/teams to assist.

0 Votes 0 ·

1 Answer

DanKershaw-5643 avatar image
0 Votes"
DanKershaw-5643 answered ·

@BrianMcCullough-3684 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.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.