I was trying to do something like this with the API to find specifc groups from the current user, but the API doesn't seem to support this type of request.
https://graph.microsoft.com/v1.0/me/memberOf?$filter=displayName eq 'Marketing Team'
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "The specified filter to the reference property query is currently not supported.",
}
}
I also tried this approach, and while it does work, it brings all the groups, regardless if the user is part of them or not.
https://graph.microsoft.com/v1.0/groups?$filter=displayName eq 'Marketing Team' or displayName eq 'HR Team' or displayName eq 'IT Team'
I'm using the group results to assign authorities, so if I filter all the groups I will always get the three groups I'm looking for and everyone will have the three roles. If I just bring all the groups from the current user and filter them after, it makes the login too slow for users that are part of +500 groups.
Is there a way to look for the current user's groups with filters, without filtering on the client side to be more efficient?
The first query will work, but you need to add $count=true
to the URL and add ConsistencyLevel
request header with value Eventual
.
https://graph.microsoft.com/v1.0/me/memberOf?$filter=displayName eq 'Marketing Team'&$count=true
ConsistencyLevel=eventual
It's so called advanced query in Graph API