更新 schemaExtension
本文内容
命名空间:microsoft.graph
更新指定 架构Extension 定义中的属性。 仅当扩展处于或Available状态时,才能对扩展InDevelopment进行附加更新。 这意味着无法从定义中删除自定义属性或目标资源类型,但可以添加新的自定义属性并更改扩展说明。
更新适用于扩展的 targetTypes 属性中包含的所有资源。 这些资源是 支持资源类型 之一。
对于委派流,只要扩展的 所有者 属性设置为已登录用户拥有的应用程序的 appId ,登录用户就可以更新架构扩展。 该应用程序可以是最初创建扩展的应用程序,也可以是已登录用户拥有的其他应用程序。
所有者 属性的此条件允许已登录用户通过他们不拥有的其他应用程序(例如 Microsoft Graph Explorer)进行更新。 使用Graph资源管理器更新 schemaExtension 资源时,请将 所有者 属性包含在 PATCH 请求正文中。 有关详细信息,请参阅 Microsoft Graph 的“已知问题 ”中的“扩展 ”部分。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Application.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
Application.ReadWrite.All 和 Directory.ReadWrite.All
HTTP 请求
PATCH /schemaExtensions/{id}
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json
请求正文
在请求正文中,提供应更新的相关字段的值。请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。为了获得最佳性能,不应包括尚未更改的现有值。
属性
类型
说明
说明
String
架构扩展的说明。
properties
extensionSchemaProperty 集合
构成架构扩展定义的属性名称和类型的集合。 仅允许进行添加性更改。
状态
String
架构扩展的生命周期状态。 创建时的初始状态是 InDevelopment。 可能的状态转换是从InDevelopment来到Available``Available向Deprecated。
targetTypes
String collection
架构扩展适用的支持扩展的 Microsoft Graph 类型集。 仅允许进行添加性更改。
响应
如果成功,此方法返回 204 No Content 响应代码。 尝试从不拥有 (且未将 所有者 属性设置为你拥有的应用程序的 appId 的应用程序运行此请求) 返回 403 Forbidden 响应代码。
示例
请求
下面展示了示例请求。 如果从不拥有的应用程序运行请求,则必须包括 所有者 属性。 在这种情况下,请将 所有者 属性设置为你拥有的应用程序的 appId 。
PATCH https://graph.microsoft.com/v1.0/schemaExtensions/exto6x7sfft_courses
Content-type: application/json
{
"owner": "ef4cb9a8-97c3-4ca7-854b-5cb5ced376fa",
"properties": [
{
"name": "courseId",
"type": "Integer"
},
{
"name": "courseName",
"type": "String"
},
{
"name": "courseType",
"type": "String"
},
{
"name": "courseSupervisors",
"type": "String"
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var user = new User
{
AdditionalData = new Dictionary<string, object>()
{
{"ext55gb1l09_msLearnCourses", "{\"courseType\":\"Admin\"}"}
}
};
await graphClient.Users["{user-id}"]
.Request()
.UpdateAsync(user);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
ext55gb1l09_msLearnCourses: {
courseType: 'Admin'
}
};
await client.api('/users/4562bcc8-c436-4f95-b7c0-4f8ce89dca5e')
.update(user);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/schemaExtensions/exto6x7sfft_courses"]]];
[urlRequest setHTTPMethod:@"PATCH"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphSchemaExtension *schemaExtension = [[MSGraphSchemaExtension alloc] init];
[schemaExtension setOwner:@"ef4cb9a8-97c3-4ca7-854b-5cb5ced376fa"];
NSMutableArray *propertiesList = [[NSMutableArray alloc] init];
MSGraphExtensionSchemaProperty *properties = [[MSGraphExtensionSchemaProperty alloc] init];
[properties setName:@"courseId"];
[properties setType:@"Integer"];
[propertiesList addObject: properties];
MSGraphExtensionSchemaProperty *properties = [[MSGraphExtensionSchemaProperty alloc] init];
[properties setName:@"courseName"];
[properties setType:@"String"];
[propertiesList addObject: properties];
MSGraphExtensionSchemaProperty *properties = [[MSGraphExtensionSchemaProperty alloc] init];
[properties setName:@"courseType"];
[properties setType:@"String"];
[propertiesList addObject: properties];
MSGraphExtensionSchemaProperty *properties = [[MSGraphExtensionSchemaProperty alloc] init];
[properties setName:@"courseSupervisors"];
[properties setType:@"String"];
[propertiesList addObject: properties];
[schemaExtension setProperties:propertiesList];
NSError *error;
NSData *schemaExtensionData = [schemaExtension getSerializedDataWithError:&error];
[urlRequest setHTTPBody:schemaExtensionData];
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();
SchemaExtension schemaExtension = new SchemaExtension();
schemaExtension.owner = "ef4cb9a8-97c3-4ca7-854b-5cb5ced376fa";
LinkedList<ExtensionSchemaProperty> propertiesList = new LinkedList<ExtensionSchemaProperty>();
ExtensionSchemaProperty properties = new ExtensionSchemaProperty();
properties.name = "courseId";
properties.type = "Integer";
propertiesList.add(properties);
ExtensionSchemaProperty properties1 = new ExtensionSchemaProperty();
properties1.name = "courseName";
properties1.type = "String";
propertiesList.add(properties1);
ExtensionSchemaProperty properties2 = new ExtensionSchemaProperty();
properties2.name = "courseType";
properties2.type = "String";
propertiesList.add(properties2);
ExtensionSchemaProperty properties3 = new ExtensionSchemaProperty();
properties3.name = "courseSupervisors";
properties3.type = "String";
propertiesList.add(properties3);
schemaExtension.properties = propertiesList;
graphClient.schemaExtensions("exto6x7sfft_courses")
.buildRequest()
.patch(schemaExtension);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewSchemaExtension()
owner := "ef4cb9a8-97c3-4ca7-854b-5cb5ced376fa"
requestBody.SetOwner(&owner)
requestBody.SetProperties( []ExtensionSchemaProperty {
msgraphsdk.NewExtensionSchemaProperty(),
SetAdditionalData(map[string]interface{}{
"name": "courseId",
"type": "Integer",
}
msgraphsdk.NewExtensionSchemaProperty(),
SetAdditionalData(map[string]interface{}{
"name": "courseName",
"type": "String",
}
msgraphsdk.NewExtensionSchemaProperty(),
SetAdditionalData(map[string]interface{}{
"name": "courseType",
"type": "String",
}
msgraphsdk.NewExtensionSchemaProperty(),
SetAdditionalData(map[string]interface{}{
"name": "courseSupervisors",
"type": "String",
}
}
schemaExtensionId := "schemaExtension-id"
graphClient.SchemaExtensionsById(&schemaExtensionId).Patch(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Users
$params = @{
}
Update-MgUser -UserId $userId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
HTTP/1.1 204 No Content
另请参阅