我尝试使用MS Graph Explorer将新的内容类型添加到列表中:
要求:
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/contenttypes
与身体:
{
"description": "MyCustomContentType's description",
"group": "List Content Types",
"hidden": false,
"id": "0x010300B8123BA6FE3D6045BF4F6DF992B6ABE7",
"name": "MyCustomContentType",
"parentId": "0x0103",
"readOnly": false,
"sealed": false
}
回复:
{
"error": {
"code": "itemNotFound",
"message": "The specified site content type was not found",
"innerError": {
"request-id": "1ac12fed-eaf3-4d03-a3c4-b44ddacada72",
"date": "2020-05-16T17:12:11"
}
}
}
还在Java 代码中使用Graph API sdk进行了尝试:
IGraphServiceClient graphClient = GraphServiceClient.builder()
.authenticationProvider(authenticationProvider)
.buildClient();
ContentType contentType = new ContentType();
contentType.name = "MyCustomContentType";
contentType.description = "MyCustomContentType's description";
contentType.group = "List Content Types";
contentType.hidden = false;
contentType.parentId = "0x0103";
contentType.id = "0x010300B8123BA6FE3D6045BF4F6DF992B6ABE7";
contentType.readOnly = false;
contentType.sealed = false;
contentType = graphClient.sites(siteId)
.lists(listId)
.contentTypes()
.buildRequest()
.post(contentType);
结果是一样的...
此外,我尝试使用REST API将内容类型添加到列表中,但遇到了另一个问题:创建了内容类型,但它忽略了传递的 id,并且总是从Item内容类型继承。此处描述的相同问题:How to create site content type with id using REST API。这似乎是 REST API 的错误。
是否可以使用 MS Graph 或 REST API 在 SharePoint 中创建内容类型?也许还有其他方法可以使用 Java 创建它?
谢谢!