Skip to content

Latest commit

 

History

History
454 lines (331 loc) · 16.5 KB

File metadata and controls

454 lines (331 loc) · 16.5 KB
title List group members
description Get a list of the group's direct members. A group can have users, organizational contacts, devices, service principals and other groups as members.
ms.localizationpriority high
author yuhko-msft
ms.reviewer mbhargav, khotzteam, aadgroupssg
ms.subservice entra-groups
doc_type apiPageType
ms.date 09/12/2024

List group members

Namespace: microsoft.graph

Get a list of the group's direct members. A group can have users, organizational contacts, devices, service principals and other groups as members. This operation is not transitive.

Important

This API has a known issue where service principals are not listed as group members in v1.0. As a workaround, use this API on the beta endpoint or use the /groups/{id}?$expand=members API. For more information, see the related known issue.

[!INCLUDE national-cloud-support]

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

[!INCLUDE permissions-table]

[!INCLUDE limited-info]

In delegated scenarios, the signed-in user must also be assigned a supported Microsoft Entra role or a custom role with the microsoft.directory/groups/members/read or microsoft.directory/groups/members/limitedRead role permission, or microsoft.directory/groups/hiddenMembers/read role permission to read hidden members. The following least privileged roles are supported for this operation:

  • Group owners
  • "Member" users
  • "Guest" users - have limited read permissions
  • Directory Readers
  • Directory Writers
  • Groups Administrator
  • User Administrator - Including hidden members
  • Exchange Administrator - Including hidden members
  • SharePoint Administrator - Including hidden members
  • Intune Administrator - Including hidden members
  • Teams Administrator - Including hidden members
  • Yammer Administrator - Including hidden members

To list the members of a hidden membership group, the Member.Read.Hidden permission is also required.

HTTP request

GET /groups/{id}/members

Optional query parameters

This method supports the $filter, $count, $select, $search, $top, and $expand OData query parameters to help customize the response.

  • OData cast is enabled. For example, /groups/{id}/members/microsoft.graph.user retrieves group members that are users.
  • $search is supported on the displayName and description properties only.
  • The use of query parameters with this API, except for $expand, is supported only with advanced query parameters. $expand isn't supported with advanced query parameters. For more information, see Advanced query capabilities on directory objects.

The default and maximum page size is 100 and 999 group objects respectively.

Request headers

Header Value
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
ConsistencyLevel eventual. This header and $count are required when using the $search, $filter, $orderby, or OData cast query parameters. It uses an index that might not be up-to-date with recent changes to the object.

Request body

Don't supply a request body for this method.

Response

If successful, this method returns a 200 OK response code and a collection of directoryObject objects in the response body.

An attempt to filter by an OData cast that represents an unsupported member type returns a 400 Bad Request error with the Request_UnsupportedQuery code. For example, /groups/{id}}/members/microsoft.graph.group when the group is a Microsoft 365 group will return this error, because Microsoft 365 groups cannot have other groups as members.

Examples

Example 1: Get the direct membership in a group

Request

The following example shows a request.

GET https://graph.microsoft.com/v1.0/groups/02bd9fd6-8f93-4758-87c3-1fb73740a315/members

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

The following example shows the response.

Note: The response object shown here might be shortened for readability.

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
  "value": [
    {
      "id": "11111111-2222-3333-4444-555555555555",
      "mail": "user1@contoso.com"
    }
  ]
}

Example 2: Get only a count of all membership

Request

The following example shows a request.

GET https://graph.microsoft.com/v1.0/groups/02bd9fd6-8f93-4758-87c3-1fb73740a315/members/$count
ConsistencyLevel: eventual

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

The following example shows the response.

HTTP/1.1 200 OK
Content-type: text/plain

893

Example 3: Use OData cast to get only a count of user membership

Request

The following example shows a request.

GET https://graph.microsoft.com/v1.0/groups/{id}/members/microsoft.graph.user/$count
ConsistencyLevel: eventual

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

The following example shows the response.

HTTP/1.1 200 OK
Content-type: text/plain

893

Example 4: Use $searchand OData cast to get user membership in groups with display names that contain the letters 'Pr' including a count of returned objects

Request

The following example shows a request.

GET https://graph.microsoft.com/v1.0/groups/{id}/members/microsoft.graph.user?$count=true&$orderby=displayName&$search="displayName:Pr"&$select=displayName,id
ConsistencyLevel: eventual

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

The following example shows the response.

Note: The response object shown here might be shortened for readability.

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users(displayName,id)",
  "@odata.count":7,
  "value":[
    {
      "displayName":"Joseph Price",
      "id":"11111111-2222-3333-4444-555555555555"
    },
    {
      "displayName":"Preston Morales",
      "id":"66666666-7777-8888-9999-000000000000"
    }
  ]
}

Example 5: Use $filter to get group membership with a display name that starts with the letter 'A' including a count of returned objects

Request

The following example shows a request.

GET https://graph.microsoft.com/v1.0/groups/{id}/members?$count=true&$filter=startswith(displayName, 'a')
ConsistencyLevel: eventual

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

The following example shows the response.

Note: The response object shown here might be shortened for readability.

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
  "@odata.count":76,
  "value":[
    {
      "displayName":"AAD Contoso Users",
      "mail":"AADContoso_Users@contoso.com"
    }
  ]
}