添加成员Add member

命名空间:microsoft.graphNamespace: microsoft.graph

通过members导航属性将成员添加到 Microsoft 365 组或安全组。Add a member to a Microsoft 365 group or a security group through the members navigation property.

您可以添加用户、组织联系人、服务主体或其他组。You can add users, organizational contacts, service principals or other groups.

重要

只能向通过云管理的安全和 Microsoft 365 组添加用户。You can only add users to security and Microsoft 365 groups managed through the cloud.

PermissionsPermissions

One of the following permissions is required to call this API.One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.To learn more, including how to choose permissions, see Permissions.

权限类型Permission type 权限(从最低特权到最高特权)Permissions (from least to most privileged)
委派(工作或学校帐户)Delegated (work or school account) GroupMember.ReadWrite.All、Group.ReadWrite.All、Directory.ReadWrite.All、Directory.AccessAsUser.AllGroupMember.ReadWrite.All, Group.ReadWrite.All, Directory.ReadWrite.All, Directory.AccessAsUser.All
委派(个人 Microsoft 帐户)Delegated (personal Microsoft account) 不支持。Not supported.
应用程序Application GroupMember.ReadWrite.All、Group.ReadWrite.All 和 Directory.ReadWrite.AllGroupMember.ReadWrite.All, Group.ReadWrite.All and Directory.ReadWrite.All

HTTP 请求HTTP request

POST /groups/{id}/members/$ref

请求标头Request headers

标头Header Value
AuthorizationAuthorization Bearer {token}.Bearer {token}. Required.Required.
Content-typeContent-type application/json.application/json. Required.Required.

请求正文Request body

在请求正文中,提供要添加的 directoryObjectusergrouporganizational contact 对象的 JSON 表示形式。In the request body, supply a JSON representation of a directoryObject, user, group, or organizational contact object to be added.

响应Response

If successful, this method returns a 204 No Content response code.If successful, this method returns a 204 No Content response code. It does not return anything in the response body.It does not return anything in the response body.

示例Examples

示例1:向组中添加成员Example 1: Add a member to a group

请求Request

下面展示了示例请求。The following is an example of the request.

POST https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
Content-type: application/json
Content-length: 30

{
  "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}

响应Response

下面展示了示例响应。The following is an example of the response.

HTTP/1.1 204 No Content

示例2:将多个成员添加到单个请求中的组Example 2: Add multiple members to a group in a single request

本示例演示如何在修补程序操作中将多个成员添加到具有 OData 绑定支持的组中。This example shows how to add multiple members to a group with OData bind support in a PATCH operation. 请注意,单个请求中最长可添加20个成员。Note that up to 20 members can be added in a single request. 不支持 POST 操作。The POST operation is not supported.

请求Request

下面展示了示例请求。The following is an example of the request.

PATCH https://graph.microsoft.com/v1.0/groups/{id}
Content-type: application/json
Content-length: 30

{
  "members@odata.bind": [
    "https://graph.microsoft.com/v1.0/directoryObjects/{id}",
    "https://graph.microsoft.com/v1.0/directoryObjects/{id}",
    "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
    ]
}

响应Response

下面展示了示例响应。The following is an example of the response.

HTTP/1.1 204 No Content