Oliver
Oliver

Reputation: 45071

Filter groupType works on groups but not on memberOf

I can get all unified groups from azure active directory quite easily, especially cause it is explicitly mentioned within the documentation:

GET https://graph.microsoft.com/v1.0/groups?filter=groupTypes/any(c:c+eq+'Unified')

And you can get all groups a user belongs to with this query:

GET https://graph.microsoft.com/v1.0/users/{user-id}/memberOf

Now lets combine those two queries to get all unified groups a user belongs to:

GET https://graph.microsoft.com/v1.0/users/{user-id}/memberOf?filter=groupTypes/any(c:c+eq+'Unified')

and you'll get back:

HTTP Status Code 400
{
    "error": {
        "code": "BadRequest",
        "message": "Filter not supported.",
        "innerError": {
            "request-id": "{request-id}",
            "date": "2018-07-06T07:29:52"
        }
    }
}

Okay, so groups supports lambda query, so let's expand on that and enhance the filter to also filter on members:

GET https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified') and members/any(u:u/id+eq+'{user-id}')

But this returns

HTTP Status Code 400
{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported Query.",
        "innerError": {
            "request-id": "{request-id}",
            "date": "2018-07-06T07:41:47"
        }
    }
}

So, why isn't any of this supported (also not in beta)?

Upvotes: 1

Views: 1019

Answers (2)

Tom Sun
Tom Sun

Reputation: 24529

So, why isn't any of this supported (also not in beta)?

$filter is not supported by List memberOf Rest API. We could get that information from List memberOf Rest API document.

This method supports the OData Query Parameters to help customize the response. $filter is not supported.

From List Group Rest API, we could know that there no any properties related to user. So you try to filter on members is not supported.

As SaurabhSharma-MSFT mentioned that you could use following way to do that.

GET https://graph.microsoft.com/v1.0/Users/{user-id}/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(c:c+eq+'Unified')

Upvotes: 1

SaurabhSharma
SaurabhSharma

Reputation: 936

Please try using the below query to get all unified groups a user belongs to -

GET https://graph.microsoft.com/v1.0/Users/{user-id}/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(c:c+eq+'Unified')

Upvotes: 1

Related Questions