命名空间:microsoft.graph
重要
Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
更新 组 对象的属性。
注意
当你用于 members@odata.bind 通过 PATCH添加成员时,此请求可能会对最近创建的组产生复制延迟。 组对象可能需要一小段时间才能跨 Microsoft Entra ID 目录副本完全复制。 在此时段内,请求向组中添加成员可能会返回错误 400 Bad Request ,并显示消息:“ 源资源对象或引用的对象之一不存在。”
要缓解此行为:
- 短暂延迟后重试 - 等待几秒钟,然后重试请求。 延迟通常是短暂的。
有关详细信息,请参阅 设计 Microsoft Entra 的最终一致性。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
Group-NestingSupport.ReadWrite.All |
Directory.ReadWrite.All、Group-PreferredDataLocation.ReadWrite.All、Group.ManageProtection.All、Group.ReadWrite.All、HardDeletionSetting.ReadWrite.Enable |
| 委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
| 应用程序 |
Group-NestingSupport.ReadWrite.All |
Directory.ReadWrite.All、Group-PreferredDataLocation.ReadWrite.All、Group.ManageProtection.All、Group.ReadWrite.All、HardDeletionSetting.ReadWrite.Enable |
特定场景的权限
- 若要将 isHardDeleteProtectionEnabled 设置为
true,应用需要 HardDeletionSetting.ReadWrite.Enable 委派或应用程序权限。 调用方还必须具有 Microsoft Entra 备份管理员角色。
-
Group.ManageProtection.All 委托权限是更新云安全组的 assignedLabels 属性和所有组的 writebackConfiguration 属性的最小特权权限。 不支持仅应用方案。
HTTP 请求
PATCH /groups/{id}
| 名称 |
类型 |
说明 |
| Authorization |
string |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
在请求正文中,仅提供应更新的属性的值。 请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。
下表指定可更新的属性。
| 属性 |
类型 |
说明 |
| allowExternalSenders |
Boolean |
默认值为“false”。 指示组织外部人员是否可以向该组发送邮件。 |
| assignedLabels |
assignedLabel 集合 |
标签 ID (标签名称) 与 Microsoft 365 组或云安全组关联的敏感度标签对的列表。 需要 Microsoft Entra ID P1 许可证。 可以在组创建或更新期间指定此属性。 但是,对于云安全组,它一旦设置就不可变。
- 对于 Microsoft 365 组,只有在调用方需要 Microsoft Graph 权限和 受支持的管理员角色的委派方案中才能更新此属性。
-
Group.ManageProtection.All 委托的权限是更新云安全组的此属性的最小特权权限。 不支持仅应用方案。
- 请参阅与 Microsoft 365 组标签的主要差异 ,了解有关管理 Microsoft 365 与云安全组的此属性的详细信息。
|
| autoSubscribeNewMembers |
Boolean |
默认值为“false”。 指示添加到组中的新成员是否将自动订阅接收电子邮件通知。 当组上的subscriptionEnabled设置为 false 时,autoSubscribeNewMembers不能为 true。 |
| 说明 |
String |
可选的组说明。 |
| displayName |
String |
组的显示名称。 此属性是在创建组时所必需的,并且在更新过程中不能清除。 |
| isHardDeleteProtectionEnabled |
布尔值 |
设置为 以 true 对现有仅云组启用硬删除保护。 启用后,不能将其设置为 false OR null。 保护在软删除后 7 天内阻止永久删除;它不会阻止软删除或还原。 |
| mailNickname |
String |
组的邮件别名,它对于组织中的 Microsoft 365 组是唯一的。 最大长度为 64 个字符。 此属性只能包含ASCII 字符集 0 - 127 中的字符,以下除外: @ () \ [] " ; : . <> , SPACE。 |
| preferredDataLocation |
String |
Microsoft 365 组的首选数据位置。 若要更新此属性,必须至少为调用用户分配以下 Microsoft Entra 角色之一:
- 用户帐户管理员
- 目录写入程序
- Exchange 管理员
- SharePoint 管理员
有关此属性详细信息,请参阅 OneDrive Online 多地理位置。 |
| securityEnabled |
Boolean |
指定组是否为安全组,包括 Microsoft 365 组。 |
| 唯一名称 |
String |
可分配给组并用作备用键的唯一标识符。 仅当设置 null 后才能更新,并且一旦设置就不可变。 |
| visibility |
String |
指定 Microsoft 365 组的可见性。 可能的是包括:专用、公用或为空(解释为公用)。 |
| welcomeMessageEnabled |
Boolean |
默认值为“true”。 指示在将新成员添加到 Microsoft 365 组时,是否向新成员发送欢迎消息。 |
| writebackConfiguration |
groupWritebackConfiguration |
指定是否将组配置为将组对象属性写回本地 Active Directory。 在 Microsoft Entra Connect 同步客户端中配置组写回时,将使用这些属性。 |
重要
- 若要更新 accessType、allowExternalSenders、autoSubscribeNewMembers、hideFromAddressLists、hideFromOutlookClients、isFavorite、isSubscribedByMail、unseenConversationsCount、unseenCount、unseenMessagesCount、welcomeMessageEnabled () 的这些属性,必须:
- 在其自己的 PATCH 请求中指定它们,而不包括上表中的其他属性
- 具有 Group.ReadWrite.All 权限 (这些属性不支持 Directory.ReadWrite.All)
- 只有与核心组管理相关的组 API 子集支持应用程序和委托的权限。 组 API 的所有其他成员(包括更新 autoSubscribeNewMembers)仅支持委派的权限。
- 在 Microsoft Exchange Server 中更新启用邮件的安全组的规则可能很复杂;若要了解详细信息,请参阅在 Exchange Server 中管理启用邮件的安全组。
- 更新 assignedLabels 时不支持应用程序权限。
Group.ManageProtection.All 是更新云安全组的 assignedLabels 的最小特权权限。
不支持在创建组期间启用 isHardDeleteProtectionEnabled 。 首先创建组,然后通过单独的 PATCH 请求启用保护。
管理扩展和关联的数据
使用此 API 管理组的 目录、架构和开放扩展 及其数据,如下所示:
- 在现有组的扩展中添加、更新和存储数据。
- 对于目录和架构扩展,可通过将自定义扩展属性的值设置为
null 来删除任何存储的数据。 对于开放扩展,请使用 删除开放扩展 API。
响应
如果成功,此方法将返回响应 204 No Content 代码 - 更新以下属性时的响应代码除外 200 OK : accessType、 allowExternalSenders、 autoSubscribeNewMembers、 hideFromAddressLists、 hideFromOutlookClients、 isFavorite、 isSubscribedByMail、 unseenConversationsCount、 unseenCount、 unseenMessagesCount、 welcomeMessageEnabled。
错误
| 状态代码 |
错误代码 |
错误消息 |
说明 |
400 Bad Request |
Request_BadRequest |
“源资源对象或引用的对象之一不存在。” |
该组是最近创建的,尚未在所有目录副本中完全复制。 此错误特定于通过) 添加 members@odata.bind 成员 (的链接写入操作。 在短暂延迟后重试请求。 |
示例
示例 1:更新组的显示名称和说明
请求
以下示例显示了一个请求。
PATCH https://graph.microsoft.com/beta/groups/0d09007d-45b2-458c-b180-880dde3a302e
Content-type: application/json
{
"description":"Contoso Life v2.0",
"displayName":"Contoso Life Renewed"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Group
{
Description = "Contoso Life v2.0",
DisplayName = "Contoso Life Renewed",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewGroup()
description := "Contoso Life v2.0"
requestBody.SetDescription(&description)
displayName := "Contoso Life Renewed"
requestBody.SetDisplayName(&displayName)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
groups, err := graphClient.Groups().ByGroupId("group-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Group group = new Group();
group.setDescription("Contoso Life v2.0");
group.setDisplayName("Contoso Life Renewed");
Group result = graphClient.groups().byGroupId("{group-id}").patch(group);
const options = {
authProvider,
};
const client = Client.init(options);
const group = {
description: 'Contoso Life v2.0',
displayName: 'Contoso Life Renewed'
};
await client.api('/groups/0d09007d-45b2-458c-b180-880dde3a302e')
.version('beta')
.update(group);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Group;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Group();
$requestBody->setDescription('Contoso Life v2.0');
$requestBody->setDisplayName('Contoso Life Renewed');
$result = $graphServiceClient->groups()->byGroupId('group-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Groups
$params = @{
description = "Contoso Life v2.0"
displayName = "Contoso Life Renewed"
}
Update-MgBetaGroup -GroupId $groupId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.group import Group
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Group(
description = "Contoso Life v2.0",
display_name = "Contoso Life Renewed",
)
result = await graph_client.groups.by_group_id('group-id').patch(request_body)
响应
以下示例显示了相应的响应。
HTTP/1.1 204 No Content
示例 2:将敏感度标签应用于 Microsoft 365 组
请求
可以使用 列表标签获取要应用于 Microsoft 365 组的标签 ID。 然后,可以使用标签 ID 更新组的 assignedLabels 属性。
注意: 仅支持委派权限方案使用此 API 将敏感度标签应用于 Microsoft 365 组。
PATCH https://graph.microsoft.com/beta/groups/{id}
Content-type: application/json
{
"assignedLabels":
[
{
"labelId" : "45cd0c48-c540-4358-ad79-a3658cdc5b88"
}
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Group
{
AssignedLabels = new List<AssignedLabel>
{
new AssignedLabel
{
LabelId = "45cd0c48-c540-4358-ad79-a3658cdc5b88",
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewGroup()
assignedLabel := graphmodels.NewAssignedLabel()
labelId := "45cd0c48-c540-4358-ad79-a3658cdc5b88"
assignedLabel.SetLabelId(&labelId)
assignedLabels := []graphmodels.AssignedLabelable {
assignedLabel,
}
requestBody.SetAssignedLabels(assignedLabels)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
groups, err := graphClient.Groups().ByGroupId("group-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Group group = new Group();
LinkedList<AssignedLabel> assignedLabels = new LinkedList<AssignedLabel>();
AssignedLabel assignedLabel = new AssignedLabel();
assignedLabel.setLabelId("45cd0c48-c540-4358-ad79-a3658cdc5b88");
assignedLabels.add(assignedLabel);
group.setAssignedLabels(assignedLabels);
Group result = graphClient.groups().byGroupId("{group-id}").patch(group);
const options = {
authProvider,
};
const client = Client.init(options);
const group = {
assignedLabels:
[
{
labelId: '45cd0c48-c540-4358-ad79-a3658cdc5b88'
}
]
};
await client.api('/groups/{id}')
.version('beta')
.update(group);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Group;
use Microsoft\Graph\Beta\Generated\Models\AssignedLabel;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Group();
$assignedLabelsAssignedLabel1 = new AssignedLabel();
$assignedLabelsAssignedLabel1->setLabelId('45cd0c48-c540-4358-ad79-a3658cdc5b88');
$assignedLabelsArray []= $assignedLabelsAssignedLabel1;
$requestBody->setAssignedLabels($assignedLabelsArray);
$result = $graphServiceClient->groups()->byGroupId('group-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Groups
$params = @{
assignedLabels = @(
@{
labelId = "45cd0c48-c540-4358-ad79-a3658cdc5b88"
}
)
}
Update-MgBetaGroup -GroupId $groupId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.group import Group
from msgraph_beta.generated.models.assigned_label import AssignedLabel
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Group(
assigned_labels = [
AssignedLabel(
label_id = "45cd0c48-c540-4358-ad79-a3658cdc5b88",
),
],
)
result = await graph_client.groups.by_group_id('group-id').patch(request_body)
响应
以下示例显示了相应的响应。
HTTP/1.1 204 No Content
示例 3:为组启用硬删除保护
硬删除保护一旦启用,就无法禁用。 使用现有的仅云组以及 特定方案的权限 中所述的权限和角色。
请求
PATCH https://graph.microsoft.com/beta/groups/0d09007d-45b2-458c-b180-880dde3a302e
Content-Type: application/json
{
"isHardDeleteProtectionEnabled": true
}
响应
HTTP/1.1 204 No Content
相关内容