9

I have a Microsoft Graph user with the following property:

"onPremisesExtensionAttributes": {
            "extensionAttribute1": "attr1",
            "extensionAttribute2": null,
            "extensionAttribute3": null,
            "extensionAttribute4": null,
             etc.
        },

I can't seem to find any documentation or examples on how to filter against this property. I've tried:

https://graph.microsoft.com/beta/users?$filter=extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/any(x:startswith(x,'attr1'))

All of them result in a Bad Request, so clearly something is wrong.

"code": "BadRequest",
"message": "Invalid filter clause",

QUESTION: how do you format a filter against onPremisesExtensionAttributes or any other property that contains a list of named properties (e.g. extensionAttribute1...n)? For a list of strings (e.g. proxyAddresses) you can just do:

$filter=proxyAddresses/any(x:startswith(x,%27smtp:myemail%27))
Michael Tucker
  • 205
  • 2
  • 10
  • 1
    Can anyone assist or have any comments on this? – Michael Tucker Jul 09 '18 at 22:53
  • 3
    I'm trying to do the same thing, but apparently you can't "Contains extensionAttributes 1-15 for the user. Note that the individual extension attributes are **neither selectable nor filterable**. For an onPremisesSyncEnabled user, this set of properties is mastered on-premises and is read-only. For a cloud-only user (where onPremisesSyncEnabled is false), these properties may be set during creation or update." – JoeS Dec 19 '18 at 11:18
  • 1
    wish this had an answer as i want to do the same thing..why didn't they make this a nav property so you could use the / syntax – Chris DaMour Mar 04 '20 at 03:07
  • 1
    Anyone got any solution? – Sumith Jose May 18 '21 at 17:46

1 Answers1

8

You can now filter on the onPremisesExtensionAttributes:

https://graph.microsoft.com/v1.0/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'

Two important points to note:

  1. You need to set the ConsistencyLevel HTTP request header to eventual. Otherwise you’ll get a 400 status code back with the following message Property 'extensionAttribute1' does not exist as a declared property or extension property.
  2. You need to include $count=true even if you don’t care about the count, otherwise you’ll get a 400 status code back with the following message Property 'extensionAttribute1' does not exist as a declared property or extension property.

Source: https://developer.microsoft.com/en-us/office/blogs/microsoft-graph-advanced-queries-for-directory-objects-are-now-generally-available/.

Gabriel
  • 1,572
  • 1
  • 17
  • 26