命名空间:microsoft.graph
将用户或服务主体添加到 Microsoft 365 或 安全组的 所有者。 所有者是一组可修改组对象的用户或服务主体。
重要提示:如果更新组所有者并为该组创建团队,则所有者与 Microsoft Team 同步需要最多花费 2 小时。 此外,如果希望所有者能够在团队中进行更改,例如创建 Planner 计划,则还需要将所有者添加为组/团队成员。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
Group.ReadWrite.All |
Directory.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
| 应用程序 |
Group.ReadWrite.All |
Directory.ReadWrite.All |
在委托方案中,还必须为登录用户分配受支持的Microsoft Entra角色或具有所需角色权限的自定义角色。 此作支持以下最低特权角色:
| Microsoft Entra角色 |
限制 |
密钥角色权限 |
| 组所有者 |
可以修改所有类型的组所有者 |
microsoft.directory/groups/owners/update |
| 用户管理员 |
只能修改用户所有者 |
microsoft.directory/groups/owners/update |
| 目录作者 |
只能修改用户所有者 |
microsoft.directory/groups/owners/update |
| 组管理员 |
可以修改所有类型的组所有者 |
microsoft.directory/groups/owners/update |
| Exchange 管理员 |
只能修改Microsoft 365 个组的所有者 |
microsoft.directory/groups.unified/owners/update |
| SharePoint 管理员 |
只能修改Microsoft 365 个组的所有者 |
microsoft.directory/groups.unified/owners/update |
| Teams 管理员 |
只能修改Microsoft 365 个组的所有者 |
microsoft.directory/groups.unified/owners/update |
| Yammer 管理员 |
只能修改Microsoft 365 个组的所有者 |
microsoft.directory/groups.unified/owners/update |
| Intune管理员 |
只能修改安全组的所有者 |
microsoft.directory/groups.security/owners/update |
| 知识管理员 |
只能修改安全组的所有者 |
microsoft.directory/groups.security/owners/update |
| 知识经理 |
只能修改安全组的所有者 |
microsoft.directory/groups.security/owners/update |
| Windows 365 管理员 |
只能修改安全组的所有者 |
microsoft.directory/groups.security/owners/update |
HTTP 请求
POST /groups/{id}/owners/$ref
| 名称 |
说明 |
| Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
| Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供要添加的用户@odata.id,或 servicePrincipal 对象的 JSON 表示形式。
响应
如果成功,此方法返回 204 No Content 响应代码。 它不会在响应正文中返回任何内容。 当对象已是组的成员时,此方法将返回 400 Bad Request 响应代码。 当添加的对象不存在时,此方法返回 404 Not Found 响应代码。
示例
请求
以下示例演示将用户添加为组所有者的请求。
POST https://graph.microsoft.com/v1.0/groups/{id}/owners/$ref
Content-type: application/json
{
"@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new ReferenceCreate
{
OdataId = "https://graph.microsoft.com/v1.0/users/{id}",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Groups["{group-id}"].Owners.Ref.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewReferenceCreate()
odataId := "https://graph.microsoft.com/v1.0/users/{id}"
requestBody.SetOdataId(&odataId)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Groups().ByGroupId("group-id").Owners().Ref().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.models.ReferenceCreate referenceCreate = new com.microsoft.graph.models.ReferenceCreate();
referenceCreate.setOdataId("https://graph.microsoft.com/v1.0/users/{id}");
graphClient.groups().byGroupId("{group-id}").owners().ref().post(referenceCreate);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const directoryObject = {
'@odata.id': 'https://graph.microsoft.com/v1.0/users/{id}'
};
await client.api('/groups/{id}/owners/$ref')
.post(directoryObject);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\ReferenceCreate;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ReferenceCreate();
$requestBody->setOdataId('https://graph.microsoft.com/v1.0/users/{id}');
$graphServiceClient->groups()->byGroupId('group-id')->owners()->ref()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Groups
$params = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/{id}"
}
New-MgGroupOwnerByRef -GroupId $groupId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.reference_create import ReferenceCreate
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ReferenceCreate(
odata_id = "https://graph.microsoft.com/v1.0/users/{id}",
)
await graph_client.groups.by_group_id('group-id').owners.ref.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
在请求正文中,提供要添加的用户@odata.id,或 servicePrincipal 对象的 JSON 表示形式。
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 204 No Content
相关内容