Matthias
Matthias

Reputation: 1032

How to query/filter from Microsoft Graph all groups where a user is owner

I would like to query from Microsoft Graph all groups where a specific user is owner. I tried the following query:
https://graph.microsoft.com/v1.0/groups?$filter=owners/any(owner: owner/id eq '4dc60fe7-8009-4131-a4e9-80dc5e86f98f')

Unfortunately this returns a 400.

Does anyone know the correct OData query? Or is this not even supported by MS Graph?

Upvotes: 3

Views: 6773

Answers (4)

Lucifer
Lucifer

Reputation: 189

You could use List ownedObjects graph API to do that where it gets the list of directory objects that are owned by the user.

But as the question is specifically about getting the list of groups that a user is owner of, you can use the below graph API where it gets the list of directory objects with odata.type as microsoft.graph.group:

GET https://graph.microsoft.com/beta/users/{User Object ID}/ownedObjects/microsoft.graph.group

And if you just want to get the group name and group ID, you can use $select,

GET https://graph.microsoft.com/beta/users/{User Object ID}/ownedObjects/microsoft.graph.group?$select=displayName,id

Upvotes: 1

GuCier
GuCier

Reputation: 7415

The memberOf endpoint returns all the groups of a given user:

https://graph.microsoft.com/v1.0/users/{ID or email}/memberOf

Will return:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
    "value": [
        {
            "id": "XXXX-XXXX-XXXX-XXXX",
            "displayName": "The group name",
            "...":"...",
            
        }
    ]
}

Upvotes: 1

alex
alex

Reputation: 335

It is possible to get all groups with owners using single API call like this: https://graph.microsoft.com/v1.0/groups?$expand=owners and then select groups which have current user in owners collection.

Upvotes: 1

RasmusW
RasmusW

Reputation: 3461

It's not possible to filter on owners. The documentation states which properties can be $filter'ed.

Look for

Supports $filter

in the description of each property.

You are going to have to read all groups, pull out their owners, and do the filtering client side.

Upvotes: 2

Related Questions