命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
更新 组 对象的属性。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Group.ReadWrite.All |
Directory.ReadWrite.All |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
Group.ReadWrite.All |
Directory.ReadWrite.All |
HTTP 请求
PATCH /groups/{id}
名称 |
类型 |
说明 |
Authorization |
string |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
在请求正文中,仅提供应更新的属性的值。 请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。
下表指定可更新的属性。
属性 |
类型 |
说明 |
allowExternalSenders |
Boolean |
默认值为“false ”。 指示组织外部人员是否可以向该组发送邮件。 |
assignedLabels |
assignedLabel 集合 |
与 Microsoft 365 组关联的敏感度标签对(标签 ID、标签名称)列表。 只有在调用方需要Microsoft Graph 权限和支持的 管理员角色的委托方案中,才能更新此属性。 |
autoSubscribeNewMembers |
Boolean |
默认值为“false ”。 指示添加到组中的新成员是否将自动订阅接收电子邮件通知。 当组上的subscriptionEnabled设置为 false 时,autoSubscribeNewMembers不能为 true 。 |
说明 |
String |
可选的组说明。 |
displayName |
String |
组的显示名称。 此属性是在创建组时所必需的,并且在更新过程中不能清除。 |
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 组的可见性。 可能的值是:专用、公用或空(解释为公用)。 |
writebackConfiguration |
groupWritebackConfiguration |
指定是否将组配置为将组对象属性写回本地 Active Directory。 在 Microsoft Entra Connect 同步客户端中配置组写回时,会使用这些属性。 |
重要
- 若要更新以下属性,必须在自己的 PATCH 请求中指定它们,而不包括上表中列出的其他属性: allowExternalSenders、 autoSubscribeNewMembers、 hideFromAddressLists、 hideFromOutlookClients、 isSubscribedByMail、 unseenCount。
- 只有与核心组管理相关的组 API 子集支持应用程序和委派权限。 组 API 的所有其他成员(包括更新 autoSubscribeNewMembers)仅支持委派的权限。
- 在 Microsoft Exchange Server 中更新启用邮件的安全组的规则可能很复杂;若要了解详细信息,请参阅在 Exchange Server 中管理启用邮件的安全组。
- 更新 assignedLabels 时不支持应用程序权限。
管理扩展和关联的数据
使用此 API 管理组的 目录、架构和开放扩展 及其数据,如下所示:
- 在现有组的扩展中添加、更新和存储数据。
- 对于目录和架构扩展,可通过将自定义扩展属性的值设置为
null
来删除任何存储的数据。 对于开放扩展,请使用 删除开放扩展 API。
响应
如果成功, 此方法返回 204 No Content
响应代码 - 更新下列属性时除了 200 OK
响应代码:allowEx在alSenders、 autoSubendNewMembers, HideFromAddressList, hideFromOutlookClients, isSubeendByMail, unseenCount。
示例
示例 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);
mgc-beta groups patch --group-id {group-id} --body '{\
"description":"Contoso Life v2.0",\
"displayName":"Contoso Life Renewed"\
}\
'
// 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);
mgc-beta groups patch --group-id {group-id} --body '{\
"assignedLabels":\
[\
{\
"labelId" : "45cd0c48-c540-4358-ad79-a3658cdc5b88"\
}\
]\
}\
'
// 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
相关内容