创建 attributeSet
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建新的 attributeSet 对象。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
CustomSecAttributeDefinition.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
CustomSecAttributeDefinition.ReadWrite.All
还必须为登录用户分配属性定义管理员 目录角色 。 默认情况下,全局管理员和其他管理员角色没有读取、定义或分配自定义安全属性的权限。
HTTP 请求
POST /directory/attributeSets
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供 attributeSet 对象的 JSON 表示形式。
下表显示可在创建 attributeSet 时配置的属性。
属性
类型
说明
说明
String
属性集的说明。 可最多为 128 个字符,并且包含 Unicode 字符。 稍后可更改。 可选。
id
String
租户中唯一的属性集的标识符。 可最多为 32 个字符,并且包含 Unicode 字符。 不能包含空格或特殊字符。 以后无法更改。 不区分大小写。 必需。
maxAttributesPerSet
Int32
可以在此属性集内定义的自定义安全属性的最大数量。 默认值为 null。 如果未指定,则管理员最多可以添加每个租户 500 个活动属性。 稍后可更改。 可选。
响应
如果成功,此方法在响应 201 Created 正文中返回 响应代码和 attributeSet 对象。
示例
示例:添加属性集
以下示例添加名为 的新属性集 Engineering 。
请求
POST https://graph.microsoft.com/beta/directory/attributeSets
Content-Type: application/json
{
"id":"Engineering",
"description":"Attributes for engineering team",
"maxAttributesPerSet":25
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var attributeSet = new AttributeSet
{
Id = "Engineering",
Description = "Attributes for engineering team",
MaxAttributesPerSet = 25
};
await graphClient.Directory.AttributeSets
.Request()
.AddAsync(attributeSet);
const options = {
authProvider,
};
const client = Client.init(options);
const attributeSet = {
id: 'Engineering',
description: 'Attributes for engineering team',
maxAttributesPerSet: 25
};
await client.api('/directory/attributeSets')
.version('beta')
.post(attributeSet);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directory/attributeSets"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphAttributeSet *attributeSet = [[MSGraphAttributeSet alloc] init];
[attributeSet setId:@"Engineering"];
[attributeSet setDescription:@"Attributes for engineering team"];
[attributeSet setMaxAttributesPerSet: 25];
NSError *error;
NSData *attributeSetData = [attributeSet getSerializedDataWithError:&error];
[urlRequest setHTTPBody:attributeSetData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
AttributeSet attributeSet = new AttributeSet();
attributeSet.id = "Engineering";
attributeSet.description = "Attributes for engineering team";
attributeSet.maxAttributesPerSet = 25;
graphClient.directory().attributeSets()
.buildRequest()
.post(attributeSet);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewAttributeSet()
id := "Engineering"
requestBody.SetId(&id)
description := "Attributes for engineering team"
requestBody.SetDescription(&description)
maxAttributesPerSet := int32(25)
requestBody.SetMaxAttributesPerSet(&maxAttributesPerSet)
result, err := graphClient.Directory().AttributeSets().Post(requestBody)
Import-Module Microsoft.Graph.Identity.DirectoryManagement
$params = @{
Id = "Engineering"
Description = "Attributes for engineering team"
MaxAttributesPerSet = 25
}
New-MgDirectoryAttributeSet -BodyParameter $params
响应
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/attributeSets/$entity",
"description": "Attributes for engineering team",
"id": "Engineering",
"maxAttributesPerSet": 25
}