List all the groups available in an organization, excluding dynamic distribution groups. To retrieve dynamic distribution groups, use the Exchange admin center.
This operation returns by default only a subset of the properties for each group. These default properties are noted in the Properties section. To get properties that are not returned by default, do a GET operation for the group and specify the properties in a $select OData query option. The hasMembersWithLicenseErrors and isArchived properties are an exception and are not returned in the $select query.
Note: This request might have replication delays for groups that were recently created, updated, or deleted.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
This method supports the $count, $expand, $filter, $orderBy, $search, $select, and $topOData query parameters to help customize the response. $skip isn't supported. The default and maximum page sizes are 100 and 999 group objects respectively. Some queries are supported only when you use the ConsistencyLevel header set to eventual and $count. For more information, see Advanced query capabilities on Azure AD directory objects.
To list only Microsoft 365 groups (aka unified groups), apply a filter on groupTypes:
GET https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified')
The $search query parameter supports tokenization only on the displayName and description fields and requires the ConsistencyLevel header. Fields other than displayName and description default to $filterstartswith behavior.
Extension properties also support query parameters as follows:
eventual. This header and $count are required when using $search, or in specific usage of $filter. For more information about the use of ConsistencyLevel and $count, see Advanced query capabilities on Azure AD directory objects.
Request body
Do not supply a request body for this method.
Response
If successful, this method returns a 200 OK response code and collection of group objects in the response body. The response includes only the default properties of each group.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
result, err := graphClient.Groups().Get(context.Background(), nil)
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestResult = $graphServiceClient->groups()->get();
Example 2: Get a filtered list of groups including the count of returned objects
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual because $count is in the request. For more information about the use of ConsistencyLevel and $count, see Advanced query capabilities on Azure AD directory objects.
Note: The $count and $search query parameters are currently not available in Azure AD B2C tenants.
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new GroupsRequestBuilderGetRequestConfiguration();
$queryParameters = new GroupsRequestBuilderGetQueryParameters();
$queryParameters->count = true;
$queryParameters->filter = "hasMembersWithLicenseErrors eq true";
$queryParameters->select = ["id","displayName"];
$headers = [
'ConsistencyLevel' => 'eventual',
];
$requestConfiguration->queryParameters = $queryParameters;
$requestConfiguration->headers = $headers;
$requestResult = $graphServiceClient->groups()->get($requestConfiguration);
The following is an example of the response which includes only the requested properties.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups(id,displayName)",
"@odata.count":2,
"value":[
{
"id":"11111111-2222-3333-4444-555555555555",
"displayName":"Contoso Group 1"
},
{
"id":"22222222-3333-4444-5555-666666666666",
"displayName":"Contoso Group 2"
}
]
}
Example 3: Get only a count of groups
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual because $count is in the request. For more information about the use of ConsistencyLevel and $count, see Advanced query capabilities on Azure AD directory objects.
Note: The $count and $search query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups/$count
ConsistencyLevel: eventual
Response
The following is an example of the response.
HTTP/1.1 200 OK
Content-type: text/plain
893
Example 4: Use $filter and $top to get one group with a display name that starts with 'a' including a count of returned objects
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual and the $count=true query string because the request has both the $orderBy and $filter query parameters. For more information about the use of ConsistencyLevel and $count, see Advanced query capabilities on Azure AD directory objects.
Note: The $count and $search query parameters are currently not available in Azure AD B2C tenants.
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new GroupsRequestBuilderGetRequestConfiguration();
$queryParameters = new GroupsRequestBuilderGetQueryParameters();
$queryParameters->filter = "startswith(displayName,%20'a')";
$queryParameters->count = true;
$queryParameters->top = 1;
$queryParameters->orderby = ["displayName"];
$headers = [
'ConsistencyLevel' => 'eventual',
];
$requestConfiguration->queryParameters = $queryParameters;
$requestConfiguration->headers = $headers;
$requestResult = $graphServiceClient->groups()->get($requestConfiguration);
Example 5: Use $search to get groups with display names that contain the letters 'Video' or a description that contains the letters 'prod' including a count of returned objects
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual because $search is in the request. For more information about the use of ConsistencyLevel and $count, see Advanced query capabilities on Azure AD directory objects.
Note: The $count and $search query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups?$search="displayName:Video" OR "description:prod"&$orderby=displayName&$count=true
ConsistencyLevel: eventual
var graphClient = new GraphServiceClient(requestAdapter);
var result = await graphClient.Groups.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Search = "\"displayName:Video\" OR \"description:prod\"";
requestConfiguration.QueryParameters.Orderby = new string []{ "displayName" };
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new GroupsRequestBuilderGetRequestConfiguration();
$queryParameters = new GroupsRequestBuilderGetQueryParameters();
$queryParameters->search = "\"displayName:Video\" OR \"description:prod\"";
$queryParameters->orderby = ["displayName"];
$queryParameters->count = true;
$headers = [
'ConsistencyLevel' => 'eventual',
];
$requestConfiguration->queryParameters = $queryParameters;
$requestConfiguration->headers = $headers;
$requestResult = $graphServiceClient->groups()->get($requestConfiguration);
The following is an example of the request that filters by the membershipRuleProcessingState to retrieve dynamic groups. You may also filter by the groupTypes properties (that is, $filter=groupTypes/any(s:s eq 'DynamicMembership')). This request requires the ConsistencyLevel header set to eventual and the $count=true query string because the request uses the not operator of the $filter query parameter. For more information about the use of ConsistencyLevel and $count, see Advanced query capabilities on Azure AD directory objects.
Note: The $count and $search query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups?$filter=mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'&$count=true&$select=id,membershipRule,membershipRuleProcessingState
ConsistencyLevel: eventual
var graphClient = new GraphServiceClient(requestAdapter);
var result = await graphClient.Groups.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Filter = "mailEnabled eq false and securityEnabled eq true and NOT) and membershipRuleProcessingState eq 'On'";
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.QueryParameters.Select = new string []{ "id","membershipRule","membershipRuleProcessingState" };
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new GroupsRequestBuilderGetRequestConfiguration();
$queryParameters = new GroupsRequestBuilderGetQueryParameters();
$queryParameters->filter = "mailEnabled eq false and securityEnabled eq true and NOT) and membershipRuleProcessingState eq 'On'";
$queryParameters->count = true;
$queryParameters->select = ["id","membershipRule","membershipRuleProcessingState"];
$headers = [
'ConsistencyLevel' => 'eventual',
];
$requestConfiguration->queryParameters = $queryParameters;
$requestConfiguration->headers = $headers;
$requestResult = $graphServiceClient->groups()->get($requestConfiguration);
GET https://graph.microsoft.com/v1.0/groups?$select=id,assignedLicenses&$filter=assignedLicenses/any()&$expand=members($select=id,displayName)
var graphClient = new GraphServiceClient(requestAdapter);
var result = await graphClient.Groups.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string []{ "id","assignedLicenses" };
requestConfiguration.QueryParameters.Filter = "assignedLicenses/any()";
requestConfiguration.QueryParameters.Expand = new string []{ "members($select=id,displayName)" };
});
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new GroupsRequestBuilderGetRequestConfiguration();
$queryParameters = new GroupsRequestBuilderGetQueryParameters();
$queryParameters->select = ["id","assignedLicenses"];
$queryParameters->filter = "assignedLicenses/any()";
$queryParameters->expand = ["members($select=id,displayName)"];
$requestConfiguration->queryParameters = $queryParameters;
$requestResult = $graphServiceClient->groups()->get($requestConfiguration);