创建设置

命名空间:microsoft.graph

基于 groupSettingTemplates 中可用的模板创建新设置。 这些设置可以在租户级别或组级别。

组设置仅适用于Microsoft 365组。 命名Group.Unified的模板可用于配置租户范围的Microsoft 365组设置,而命名Group.Unified.Guest的模板可用于配置特定于组的设置。

权限

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限

权限类型 权限(从最低特权到最高特权)
委派(工作或学校帐户) Directory.ReadWrite.All
委派(个人 Microsoft 帐户) 不支持。
Application Directory.ReadWrite.All

HTTP 请求

创建租户范围的设置。

POST /groupSettings

创建特定于组的设置。

POST /groups/{id}/settings

请求标头

名称 说明
Authorization Bearer {token}。必需。
Content-Type application/json

请求正文

在请求正文中,提供 groupSetting 对象的 JSON 表示形式。 显示名称、模板Id 和说明继承自引用的 groupSettingTemplates 对象。 只能从默认值更改值属性。

创建 groupSetting 对象时需要以下属性。

参数 类型 说明
templateId 字符串 用于创建此组级设置对象的租户级 groupSettingTemplates 对象的唯一标识符。 只读。
values settingValue 集合 与引用的 groupSettingTemplates 对象中的名称和 defaultValue 属性对应的 名称-值对的集合。

响应

如果成功,此方法将在响应正文中返回 201 Created 响应代码和 groupSetting 对象。

示例 1:为租户中的所有Microsoft 365组创建新设置

请求

只有命名Group.UnifiedgroupSettingTemplates 对象才能应用于租户级别的所有Microsoft 365组。

POST https://graph.microsoft.com/v1.0/groupSettings
Content-type: application/json

{
    "templateId": "62375ab9-6b52-47ed-826b-58e47e0e304b",
    "values": [
        {
            "name": "GuestUsageGuidelinesUrl",
            "value": "https://privacy.contoso.com/privacystatement"
        },
        {
            "name": "EnableMSStandardBlockedWords",
            "value": "true"
        },
        {
            "name": "EnableMIPLabels",
            "value": "true"
        },
        {
            "name": "PrefixSuffixNamingRequirement",
            "value": "[Contoso-][GroupName]"
        }
    ]
}

响应

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

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groupSettings/$entity",
    "id": "844d252c-4de2-43eb-a784-96df77231aae",
    "displayName": null,
    "templateId": "62375ab9-6b52-47ed-826b-58e47e0e304b",
    "values": [
        {
            "name": "GuestUsageGuidelinesUrl",
            "value": "https://privacy.contoso.com/privacystatement"
        },
        {
            "name": "EnableMSStandardBlockedWords",
            "value": "true"
        },
        {
            "name": "EnableMIPLabels",
            "value": "true"
        },
        {
            "name": "PrefixSuffixNamingRequirement",
            "value": "[Contoso-][GroupName]"
        }
    ]
}

displayName 属性和其他名称值对将填充与 templateId 匹配的 groupSettingTemplates 对象中的默认值。

示例 2:创建用于阻止特定Microsoft 365组的来宾的设置

请求

只有命名Group.Unified.GuestgroupSettingTemplates 对象才能应用于特定Microsoft 365组。

POST https://graph.microsoft.com/v1.0/groups/055a5d18-a3a9-4338-b9c5-de92559b7ebf/settings
Content-type: application/json

{
    "templateId": "08d542b9-071f-4e16-94b0-74abb372e3d9",
    "values": [
        {
            "name": "AllowToAddGuests",
            "value": "false"
        }
    ]
}

在请求正文中,提供 groupSetting 对象的 JSON 表示形式。

响应

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

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groupSettings/$entity",
    "id": "a06fa228-3042-4662-bd09-33e298da1afe",
    "displayName": null,
    "templateId": "08d542b9-071f-4e16-94b0-74abb372e3d9",
    "values": [
        {
            "name": "AllowToAddGuests",
            "value": "false"
        }
    ]
}