Felix Gerber
Felix Gerber

Reputation: 1651

Azure Graph API Filter by array value

I'm trying to execute an query on my users of my Azure B2C Active Directory.

So far everything works fine with the following query:

https://graph.windows.net/myTentant/users?$filter=
startswith(displayName,'test')%20
or%20startswith(givenName,'test')%20
or%20startswith(surname,'test')%20
or%20startswith(mail,'test')%20
or%20startswith(userPrincipalName,'test')
&api-version=1.6

The thing about that is, that this properties are just simple values like this:

"displayName: "testValue",
"givenName": "testValue",
"displayName: "testValue",
"surname": "testValue",
"mail: "testValue",
"userPrincipalName": "testValue",

In my case I need to use one more statement, in which I need to check an array if it contains 'test' like the others. This array look like that:

        "signInNames": [
            {
                "type": "emailAddress",
                "value": "[email protected]"
            },                {
                "type": "emailAddress",
                "value": "[email protected]"
            }
        ]

I Already search in the official documentation but had no luck.... Any ideas?

Upvotes: 5

Views: 5171

Answers (1)

Allen Wu
Allen Wu

Reputation: 16438

In theory, we should use the following format to determine whether the value starts with "test".

GET https://graph.windows.net/myorganization/users?$filter=signInNames/any(c:startswith(c/value, 'test'))

Unfortunately, it will show an error: value only supports equals-match. PrefixMatch is not supported.

And the contains string operator is currently not supported on any Microsoft Graph resources. So we can't use contains neither.

You need to use equal to find the exact match data:

GET https://graph.windows.net/myorganization/users?$filter=signInNames/any(c:c/value eq '***')

It is not a solution. But there seems not to be a way to meet your needs.

Maybe you could query all the signInNames and handle them in your code.

Upvotes: 4

Related Questions