列出组

命名空间:microsoft.graph

重要

Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

列出组织中可用的所有组,不包括动态通讯组。 要检索动态通讯组,请 使用 Exchange 管理中心

此操作在默认情况下仅返回每个组的一部分较常用属性。 这些默认属性将记录在属性部分中。 若要获取默认返回的属性,请对组执行 GET 操作,并在 $select OData 查询选项中指定这些属性。 hasMembersWithLicenseErrorsisArchived 属性为异常,不会在 $select 查询中返回。

此 API 可用于以下国家级云部署

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) GroupMember.Read.All Group.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All、Group.Read.All
委派(个人 Microsoft 帐户) 不支持。 不支持。
应用程序 GroupMember.Read.All Directory.Read.All、Directory.ReadWrite.All、Group.Read.All、Group.ReadWrite.All

HTTP 请求

GET /groups

可选的查询参数

此方法支持 $count、、$expand$filter$orderby$search$select$topOData 查询参数来帮助自定义响应。 不支持 $skip。 默认和最大页面大小分别为 100 和 999 个组对象。 只有将 ConsistencyLevel 标头设置为 eventual$count 时,才支持某些查询。 有关详细信息,请参阅 目录对象的高级查询功能

若要仅列出 Microsoft 365 组 (统一组) ,请对 groupTypes 应用筛选器:

GET https://graph.microsoft.com/beta/groups?$filter=groupTypes/any(c:c+eq+'Unified')

$search查询参数仅支持对 displayName 说明字段进行标记化,并且需要 ConsistencyLevel 标头。 除 displayNamedescription 以外的字段默认为$filterstartsWith行为。

扩展属性还支持查询参数,如下所示:

扩展类型 备注
架构扩展 仅通过 $select 返回。
开放扩展 仅与 $expand一起返回。
目录扩展 默认返回。

有关 OData 查询选项的详细信息,请参阅 OData 查询参数。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

按组类型筛选

组类型 API 请求
Microsoft 365 (统一) 组 GET/groups?$filter=groupTypes/any(c:c+eq+'Unified')
安全组 GET/groups?$filter=mailEnabled eq false&securityEnabled eq true
启用邮件的安全组 获取/groups?$filter=NOT groupTypes/any(c:c eq 'Unified') and mailEnabled eq true and securityEnabled eq true&$count=true **
通讯组 获取/groups?$filter=NOT groupTypes/any(c:c eq 'Unified') and mailEnabled eq true and securityEnabled eq false&$count=true **

** :仅 高级查询功能支持此示例。

请求标头

名称 说明
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权
ConsistencyLevel 最终。 当使用 $search$filter 的特定用法时,需要此标头和 $count。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

请求正文

请勿提供此方法的请求正文。

响应

如果成功,此方法在响应正文中返回 200 OK 响应代码和 group 对象集合。 该响应仅包括每个组的默认属性。

示例

示例 1:获取组列表

请求

以下示例显示了一个请求。

GET https://graph.microsoft.com/beta/groups

响应

以下示例显示了相应的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。 在实际调用中会返回每个组的所有默认属性。

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

{
   "@odata.context":"https://graph.microsoft.com/beta/$metadata#groups",
   "value":[
      {
         "id":"45b7d2e7-b882-4a80-ba97-10b7a63b8fa4",
         "deletedDateTime":null,
         "classification":null,
         "createdDateTime":"2018-12-22T02:21:05Z",
         "description":"Self help community for golf",
         "displayName":"Golf Assist",
         "expirationDateTime":null,
         "groupTypes":[
            "Unified"
         ],
         "isAssignableToRole":null,
         "mail":"golfassist@contoso.com",
         "mailEnabled":true,
         "mailNickname":"golfassist",
         "membershipRule":null,
         "membershipRuleProcessingState":null,
         "onPremisesLastSyncDateTime":null,
         "onPremisesSecurityIdentifier":null,
         "onPremisesSyncEnabled":null,
         "preferredDataLocation":"CAN",
         "preferredLanguage":null,
         "proxyAddresses":[
            "smtp:golfassist@contoso.com",
            "SMTP:golfassist@contoso.com"
         ],
         "renewedDateTime":"2018-12-22T02:21:05Z",
         "resourceBehaviorOptions":[
         ],
         "resourceProvisioningOptions":[
         ],
         "securityEnabled":false,
         "serviceProvisioningErrors": [
         ],
         "theme":null,
         "visibility":"Public",
         "onPremisesProvisioningErrors":[
         ]
      },
      {
         "id":"d7797254-3084-44d0-99c9-a3b5ab149538",
         "deletedDateTime":null,
         "classification":null,
         "createdDateTime":"2018-11-19T20:29:40Z",
         "description":"Talk about golf",
         "displayName":"Golf Discussion",
         "expirationDateTime":null,
         "groupTypes":[
         ],
         "isAssignableToRole":null,
         "mail":"golftalk@contoso.com",
         "mailEnabled":true,
         "mailNickname":"golftalk",
         "membershipRule":null,
         "membershipRuleProcessingState":null,
         "onPremisesLastSyncDateTime":null,
         "onPremisesSecurityIdentifier":null,
         "onPremisesSyncEnabled":null,
         "preferredDataLocation":"CAN",
         "preferredLanguage":null,
         "proxyAddresses":[
            "smtp:golftalk@contoso.com",
            "SMTP:golftalk@contoso.com"
         ],
         "renewedDateTime":"2018-11-19T20:29:40Z",
         "resourceBehaviorOptions":[
         ],
         "resourceProvisioningOptions":[
         ],
         "securityEnabled":false,
         "serviceProvisioningErrors": [
         ],
         "theme":null,
         "visibility":null,
         "onPremisesProvisioningErrors":[
         ]
      }
   ]
}

示例 2:获取组的筛选列表(包括返回的对象数)

请求

以下示例显示了一个请求。 此请求要求将 ConsistencyLevel 标头设置为 eventual,因为在请求中有 $count。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

注意:$count$search 查询参数当前在 Azure AD B2C 租户中不可用。

GET https://graph.microsoft.com/beta/groups?$count=true&$filter=hasMembersWithLicenseErrors+eq+true&$select=id,displayName
ConsistencyLevel: eventual

响应

下面是一个仅包括所请求的属性的响应示例。

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

{
   "@odata.context":"https://graph.microsoft.com/beta/$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"
      }
   ]
}

示例 3:仅获取组的计数

请求

以下示例显示了一个请求。 此请求要求将 ConsistencyLevel 标头设置为 eventual,因为在请求中有 $count。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

注意:$count$search 查询参数当前在 Azure AD B2C 租户中不可用。

GET https://graph.microsoft.com/beta/groups/$count
ConsistencyLevel: eventual

响应

以下示例显示了相应的响应。

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

893

示例 4:使用 $filter 和 $top 获取显示名称以“a”开头(包括返回的对象数)的组。

请求

以下示例显示了一个请求。 此请求需要将 ConsistencyLevel 标头设置为 eventual$count=true 查询字符串,因为请求同时具有 $orderby$filter 查询参数。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

注意:$count$search 查询参数当前在 Azure AD B2C 租户中不可用。

GET https://graph.microsoft.com/beta/groups?$filter=startswith(displayName, 'a')&$count=true&$top=1&$orderby=displayName
ConsistencyLevel: eventual

响应

以下示例显示了相应的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

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

{
   "@odata.context":"https://graph.microsoft.com/beta/$metadata#groups",
   "@odata.count":1,
   "value":[
      {
         "displayName":"a",
         "mailNickname":"a241"
      }
   ]
}

示例 5:使用$search获取显示名称包含字母“Video”的组或包含字母“prod”的说明(包括返回的对象计数)

请求

以下示例显示了一个请求。 此请求要求将 ConsistencyLevel 标头设置为 eventual,因为在请求中有 $search。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

注意:$count$search 查询参数当前在 Azure AD B2C 租户中不可用。

GET https://graph.microsoft.com/beta/groups?$search="displayName:Video" OR "description:prod"&$orderby=displayName&$count=true
ConsistencyLevel: eventual

响应

以下示例显示了相应的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

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

{
   "@odata.context":"https://graph.microsoft.com/beta/$metadata#groups",
   "@odata.count":1396,
   "value":[
      {
         "displayName":"SFA Videos",
         "mail":"SFAVideos@service.contoso.com",
         "mailNickname":"SFAVideos"
      },
      {
         "description":"Video Production",
         "displayName":"Video Production",
         "mail":"videoprod@service.contoso.com",
         "mailNickname":"VideoProduction"
      }
   ]
}

示例 6:列出动态组

请求

以下示例显示了按 membershipRuleProcessingState 筛选以检索动态组的请求。 也可以按 groupTypes 属性 (即 $filter=groupTypes/any(s:s eq 'DynamicMembership')) 进行筛选。 此请求需要将 ConsistencyLevel 标头设置为 eventual$count=true 查询字符串,因为此请求使用了 $filter 查询参数的 not 运算符。 有关使用 ConsistencyLevel$count的详细信息,请参阅 目录对象的高级查询功能

注意:$count$search 查询参数当前在 Azure AD B2C 租户中不可用。

GET https://graph.microsoft.com/beta/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

响应

以下示例显示了相应的响应。

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

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#groups(id,membershipRule,membershipRuleProcessingState)",
    "@odata.count": 1,
    "value": [
        {
            "@odata.id": "https://graph.microsoft.com/v2/84841066-274d-4ec0-a5c1-276be684bdd3/directoryObjects/e9f4a701-e7b5-4401-a0ca-5bd5f3cdcf4b/Microsoft.DirectoryServices.Group",
            "id": "e9f4a701-e7b5-4401-a0ca-5bd5f3cdcf4b",
            "membershipRule": "(user.userType -contains \"Guest\" and user.accountEnabled -eq true) or (user.city -eq \"Nairobi\")",
            "membershipRuleProcessingState": "On"
        }
    ]
}

示例 7:列出具有任何许可证的任何组并获取组的成员

请求

GET https://graph.microsoft.com/beta/groups?$select=id,assignedLicenses&$filter=assignedLicenses/any()&$expand=members($select=id,displayName)

响应

以下示例显示了相应的响应。

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

{
  "@odata.context": "https://graph.microsoft.com/beta/$metadata#groups(id,assignedLicenses,members())",
  "value": [
    {
      "id": "5caf712c-8483-4b3d-8384-d8da988c0ca4",
      "assignedLicenses": [
        {
          "disabledPlans": [],
          "skuId": "6fd2c87f-b296-42f0-b197-1e91e994b900"
        }
      ],
      "members": [
        {
          "@odata.type": "#microsoft.graph.user",
          "id": "0952e4c8-432f-4950-a65c-769c45993527"
        },
        {
          "@odata.type": "#microsoft.graph.user",
          "id": "49e373b6-4717-40c6-ad43-843c45a258f0"
        }
      ]
    },
    {
      "id": "aae8ec2a-5a08-4013-ae70-fafbb5c20de1",
      "assignedLicenses": [
        {
          "disabledPlans": [
            "7547a3fe-08ee-4ccb-b430-5077c5041653"
          ],
          "skuId": "18181a46-0d4e-45cd-891e-60aabd171b4e"
        }
      ],
      "members": []
    }
  ]
}