创建内容类型
本文内容
命名空间:microsoft.graph
在网站[中创建新的 contentType。][] [][]
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Sites.Manage.All、Sites.FullControl.All
委派(个人 Microsoft 帐户)
不支持
应用程序
Sites.Manage.All、Sites.FullControl.All
HTTP 请求
POST /sites/{site-id}/contentTypes
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json. Required.
请求正文
在请求正文中,提供要创建的 contentType 资源的 JSON 表示形式。
响应
如果成功,此方法在响应 201 Created 正文中返回 响应代码和 contentType 对象。
示例
以下示例演示如何创建新的泛型内容类型。
请求
POST https://graph.microsoft.com/v1.0/sites/{id}/contentTypes
Content-Type: application/json
{
"name": "docSet",
"description": "custom docset",
"base": {
"name": "Document Set",
"id": "0x0120D520"
},
"group": "Document Set Content Types"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var contentType = new ContentType
{
Name = "docSet",
Description = "custom docset",
Base = new ContentType
{
Name = "Document Set",
Id = "0x0120D520"
},
Group = "Document Set Content Types"
};
await graphClient.Sites["{site-id}"].ContentTypes
.Request()
.AddAsync(contentType);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const contentType = {
name: 'docSet',
description: 'custom docset',
base: {
name: 'Document Set',
id: '0x0120D520'
},
group: 'Document Set Content Types'
};
await client.api('/sites/{id}/contentTypes')
.post(contentType);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/sites/{id}/contentTypes"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphContentType *contentType = [[MSGraphContentType alloc] init];
[contentType setName:@"docSet"];
[contentType setDescription:@"custom docset"];
MSGraphContentType *base = [[MSGraphContentType alloc] init];
[base setName:@"Document Set"];
[base setId:@"0x0120D520"];
[contentType setBase:base];
[contentType setGroup:@"Document Set Content Types"];
NSError *error;
NSData *contentTypeData = [contentType getSerializedDataWithError:&error];
[urlRequest setHTTPBody:contentTypeData];
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();
ContentType contentType = new ContentType();
contentType.name = "docSet";
contentType.description = "custom docset";
ContentType base = new ContentType();
base.name = "Document Set";
base.id = "0x0120D520";
contentType.base = base;
contentType.group = "Document Set Content Types";
graphClient.sites("{id}").contentTypes()
.buildRequest()
.post(contentType);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewContentType()
name := "docSet"
requestBody.SetName(&name)
description := "custom docset"
requestBody.SetDescription(&description)
base := msgraphsdk.NewContentType()
requestBody.SetBase(base)
name := "Document Set"
base.SetName(&name)
id := "0x0120D520"
base.SetId(&id)
group := "Document Set Content Types"
requestBody.SetGroup(&group)
siteId := "site-id"
result, err := graphClient.SitesById(&siteId).ContentTypes().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Sites
$params = @{
Name = "docSet"
Description = "custom docset"
Base = @{
Name = "Document Set"
Id = "0x0120D520"
}
Group = "Document Set Content Types"
}
New-MgSiteContentType -SiteId $siteId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"id": "0x01002A2479FF33DD4BC3B1533A012B653717",
"name": "docSet",
"group":"Document Set Content Types",
"description" : "custom docset",
"base": {
"name": "Document Set",
"id": "0x0120D520"
}
}