This API returns up to 11,000 group IDs. If more than 11,000 results are available, it returns a 400 Bad Request error with the Directory_ResultSizeLimitExceeded error code. As a workaround, use the List group transitive memberOf API.
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Group memberships for a directory object
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
User.ReadBasic.All and GroupMember.Read.All, User.Read.All and GroupMember.Read.All, User.ReadBasic.All and Group.Read.All, User.Read.All and Group.Read.All, Directory.Read.All
Delegated (personal Microsoft account)
Not supported.
Application
User.Read.All and GroupMember.Read.All, User.Read.All and Group.Read.All, Directory.Read.All
Group memberships for a user
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
User.ReadBasic.All and GroupMember.Read.All, User.Read.All and GroupMember.Read.All, User.ReadBasic.All and Group.Read.All, User.Read.All and Group.Read.All, Directory.Read.All
Delegated (personal Microsoft account)
Not supported.
Application
User.Read.All and GroupMember.Read.All, User.Read.All and Group.Read.All, Directory.Read.All
Group memberships for a directory object (user, group, service principal, or organizational contact).
POST /directoryObjects/{id}/getMemberGroups
Group memberships for the signed-in user or other users.
POST /me/getMemberGroups
POST /users/{id | userPrincipalName}/getMemberGroups
Group memberships for a group.
POST /groups/{id}/getMemberGroups
Group memberships for a service principal.
POST /servicePrincipals/{id}/getMemberGroups
Group memberships for an organizational contact.
POST /contacts/{id}/getMemberGroups
Group memberships for a device.
POST /devices/{id}/getMemberGroups
Request headers
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
In the request body, provide a JSON object with the following parameters.
Parameter
Type
Description
securityEnabledOnly
Boolean
true to specify that only security groups that the entity is a member of should be returned; false to specify that all groups and directory roles that the entity is a member of should be returned. true can be specified only for users or service principals to return security-enabled groups.
Response
If successful, this method returns 200 OK response code and String collection object in the response body.
Examples
Example 1: Check group memberships for a directory object
POST https://graph.microsoft.com/v1.0/directoryObjects/0049d944-a805-4680-9f54-3ab292090309/getMemberGroups
Content-type: application/json
{
"securityEnabledOnly": false
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.DirectoryObjects.Item.GetMemberGroups.GetMemberGroupsPostRequestBody
{
SecurityEnabledOnly = false,
};
var result = await graphClient.DirectoryObjects["{directoryObject-id}"].GetMemberGroups.PostAsync(requestBody);
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc directory-objects get-member-groups post --directory-object-id {directoryObject-id} --body '{\
"securityEnabledOnly": false\
}\
'
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new GetMemberGroupsPostRequestBody();
$requestBody->setSecurityEnabledOnly(false);
$result = $graphServiceClient->directoryObjects()->byDirectoryObjectId('directoryObject-id')->getMemberGroups()->post($requestBody)->wait();
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = GetMemberGroupsPostRequestBody(
security_enabled_only = False,
)
result = await graph_client.directory_objects.by_directory_object_id('directoryObject-id').get_member_groups.post(body = request_body)
POST https://graph.microsoft.com/v1.0/me/getMemberGroups
Content-type: application/json
{
"securityEnabledOnly": true
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Me.GetMemberGroups.GetMemberGroupsPostRequestBody
{
SecurityEnabledOnly = true,
};
var result = await graphClient.Me.GetMemberGroups.PostAsync(requestBody);
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new GetMemberGroupsPostRequestBody();
$requestBody->setSecurityEnabledOnly(true);
$result = $graphServiceClient->me()->getMemberGroups()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Users.Actions
$params = @{
securityEnabledOnly = $true
}
# A UPN can also be used as -UserId.
Get-MgUserMemberGroup -UserId $userId -BodyParameter $params
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = GetMemberGroupsPostRequestBody(
security_enabled_only = True,
)
result = await graph_client.me.get_member_groups.post(body = request_body)