创建 allowedValue
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建新的 allowedValue 对象。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
CustomSecAttributeDefinition.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
CustomSecAttributeDefinition.ReadWrite.All
还必须为登录用户分配属性定义管理员 目录角色 。 默认情况下,全局管理员和其他管理员角色没有读取、定义或分配自定义安全属性的权限。
HTTP 请求
POST /directory/customSecurityAttributeDefinitions/{customSecurityAttributeDefinitionId}/allowedValues
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供 allowedValue 对象的 JSON 表示形式。
下表显示创建 allowedValue 时所需的属性。
属性
类型
说明
id
String
预定义值的标识符。 可最多为 64 个字符,并且包含 Unicode 字符。 可以包含空格,但不允许使用某些特殊字符。 以后无法更改。 区分大小写。 必需。
isActive
布尔
指示预定义值是处于活动状态还是已停用。 如果设置为 false ,则此预定义值不能分配给任何其他受支持的目录对象。 必需。
响应
如果成功,此方法在响应 201 Created 正文中返回 响应代码和 allowedValue 对象。
示例
示例:添加预定义值
以下示例向自定义安全属性定义添加预定义值。
属性集:Engineering
属性:Project
预定义值: Alpine
请求
POST https://graph.microsoft.com/beta/directory/customSecurityAttributeDefinitions/Engineering_Project/allowedValues
Content-Type: application/json
{
"id":"Alpine",
"isActive":"true"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var allowedValue = new AllowedValue
{
Id = "Alpine",
IsActive = true
};
await graphClient.Directory.CustomSecurityAttributeDefinitions["{customSecurityAttributeDefinition-id}"].AllowedValues
.Request()
.AddAsync(allowedValue);
const options = {
authProvider,
};
const client = Client.init(options);
const allowedValue = {
id: 'Alpine',
isActive: 'true'
};
await client.api('/directory/customSecurityAttributeDefinitions/Engineering_Project/allowedValues')
.version('beta')
.post(allowedValue);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directory/customSecurityAttributeDefinitions/Engineering_Project/allowedValues"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphAllowedValue *allowedValue = [[MSGraphAllowedValue alloc] init];
[allowedValue setId:@"Alpine"];
[allowedValue setIsActive:@"true"];
NSError *error;
NSData *allowedValueData = [allowedValue getSerializedDataWithError:&error];
[urlRequest setHTTPBody:allowedValueData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
AllowedValue allowedValue = new AllowedValue();
allowedValue.id = "Alpine";
allowedValue.isActive = false;
graphClient.directory().customSecurityAttributeDefinitions("Engineering_Project").allowedValues()
.buildRequest()
.post(allowedValue);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewAllowedValue()
id := "Alpine"
requestBody.SetId(&id)
isActive := "true"
requestBody.SetIsActive(&isActive)
customSecurityAttributeDefinitionId := "customSecurityAttributeDefinition-id"
result, err := graphClient.Directory().CustomSecurityAttributeDefinitionsById(&customSecurityAttributeDefinitionId).AllowedValues().Post(requestBody)
Import-Module Microsoft.Graph.Identity.DirectoryManagement
$params = @{
Id = "Alpine"
IsActive = "true"
}
New-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId $customSecurityAttributeDefinitionId -BodyParameter $params
响应
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#directory/customSecurityAttributeDefinitions('Engineering_Project')/allowedValues/$entity",
"id": "Alpine",
"isActive": true
}