创建 extensionProperty
本文内容
命名空间:microsoft.graph
创建新的 extensionProperty 定义。 可以使用此操作将自定义属性值添加到 extensionProperty 中定义的目标对象类型,使用标准创建和更新目标对象的请求。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Application.ReadWrite.All
委派(个人 Microsoft 帐户)
Application.ReadWrite.All
应用程序
Application.ReadWrite.OwnedBy、Application.ReadWrite.All、Directory.Read.All
HTTP 请求
POST /applications/{application ObjectId}/extensionProperties
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供具有以下属性的 extensionProperty 对象。
属性
类型
说明
DataType
String
指定扩展属性可以保存的值的数据类型。 支持以下值。 不可为 null。 Binary - 最大 256 字节数BooleanDateTime - 必须以 ISO 8601 格式指定。 存储为 UTC 格式。Integer - 32 位值。LargeInteger - 64 位值。String - 最大 256 个字符
name
字符串
扩展属性的名称。 不可为 null。
targetObjects
字符串集合
支持以下值。 不可为 null。 UserGroupOrganizationDeviceApplication
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和新的 extensionProperty 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/v1.0/applications/fd918e4b-c821-4efb-b50a-5eddd23afc6f/extensionProperties
Content-type: application/json
{
"name": "jobGroup",
"dataType": "String",
"targetObjects": [
"User"
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var extensionProperty = new ExtensionProperty
{
Name = "jobGroup",
DataType = "String",
TargetObjects = new List<String>()
{
"User"
}
};
await graphClient.Applications["{application-id}"].ExtensionProperties
.Request()
.AddAsync(extensionProperty);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const extensionProperty = {
name: 'jobGroup',
dataType: 'String',
targetObjects: [
'User'
]
};
await client.api('/applications/fd918e4b-c821-4efb-b50a-5eddd23afc6f/extensionProperties')
.post(extensionProperty);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/applications/fd918e4b-c821-4efb-b50a-5eddd23afc6f/extensionProperties"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphExtensionProperty *extensionProperty = [[MSGraphExtensionProperty alloc] init];
[extensionProperty setName:@"jobGroup"];
[extensionProperty setDataType:@"String"];
NSMutableArray *targetObjectsList = [[NSMutableArray alloc] init];
[targetObjectsList addObject: @"User"];
[extensionProperty setTargetObjects:targetObjectsList];
NSError *error;
NSData *extensionPropertyData = [extensionProperty getSerializedDataWithError:&error];
[urlRequest setHTTPBody:extensionPropertyData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ExtensionProperty extensionProperty = new ExtensionProperty();
extensionProperty.name = "jobGroup";
extensionProperty.dataType = "String";
LinkedList<String> targetObjectsList = new LinkedList<String>();
targetObjectsList.add("User");
extensionProperty.targetObjects = targetObjectsList;
graphClient.applications("fd918e4b-c821-4efb-b50a-5eddd23afc6f").extensionProperties()
.buildRequest()
.post(extensionProperty);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewExtensionProperty()
name := "jobGroup"
requestBody.SetName(&name)
dataType := "String"
requestBody.SetDataType(&dataType)
requestBody.SetTargetObjects( []String {
"User",
}
applicationId := "application-id"
result, err := graphClient.ApplicationsById(&applicationId).ExtensionProperties().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Applications
$params = @{
Name = "jobGroup"
DataType = "String"
TargetObjects = @(
"User"
)
}
New-MgApplicationExtensionProperty -ApplicationId $applicationId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 extensionProperty 对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications('fd918e4b-c821-4efb-b50a-5eddd23afc6f')/extensionProperties/$entity",
"id": "da38c7b1-133e-4a79-abcd-e2fd586ce621",
"deletedDateTime": null,
"appDisplayName": "b2c-extensions-app. Do not modify. Used by AADB2C for storing user data.",
"dataType": "String",
"isSyncedFromOnPremises": false,
"name": "extension_25883231668a43a780b25685c3f874bc_jobGroup",
"targetObjects": [
"User"
]
}