I need to filter users with the onPremisesExtensionAttributes [extensionAttribute6] is there a graph API call for it?
-
2Refer to this [doc](https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#properties), it said 'the individual extension attributes are neither selectable nor filterable'. – Tiny Wang Feb 18 '21 at 15:18
-
Hi, if my answer is helpful, you can mark it as accepted. Thank you! – Allen Wu Feb 22 '21 at 02:13
2 Answers
It looks like they've updated the BETA Graph API so that extension attributes (onPremisesExtensionAttributes) are now filterable.
Try the below in Graph Explorer. You'll need to change the extensionAttribute1 eq 'Employee' part to a query that will actually work in your active directory environment.
https://graph.microsoft.com/beta/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'Employee'&$orderBy=displayName&$select=displayName,mail,onPremisesExtensionAttributes
Please note that this is the BETA Graph API so I guess that means Microsoft hasn't finalized it, so it might change or never get fully released.
EDIT: I also just learned that if you're using this filter via the Graph API, you must add the following header or you'll an error:
client.DefaultRequestHeaders.Add("ConsistencyLevel", "eventual");
The Graph Explorer has this header by default, I guess.
Here's where I found this answer: Get Extended Properties on User using Microsoft Graph
Here's the error I was getting: Property 'extensionAttribute1' does not exist as a declared property or extension property.

- 146
- 1
- 9
As @Tinywa suggested in the comment:
onPremisesExtensionAttributes contains extensionAttributes 1-15 for the user. Note that the individual extension attributes are neither selectable nor filterable.
You can get all the results first and use your own code logic to filter them.
Or you can consider using extensionProperty as a workaround. Create the extensionProperty
and assign value for the users, and then query users with filtering with this extensionProperty
. For detailed steps to create extensionProperty
and assign value for users, you can refer to this answer.

- 15,529
- 1
- 9
- 20