コンテンツ タイプを作成する
[アーティクル]
01/20/2022
3 人の共同作成者
この記事の内容
名前空間: microsoft.graph
サイトに新しい contentType を作成 [します][]。
アクセス許可
この API を呼び出すには、次のいずれかのアクセス許可が必要です。アクセス許可の選択方法などの詳細については、「アクセス許可 」を参照してください。
アクセス許可の種類
アクセス許可 (特権の小さいものから大きいものへ)
委任 (職場または学校のアカウント)
Sites.Manage.All、Sites.FullControl.All
委任 (個人用 Microsoft アカウント)
サポート対象外
アプリケーション
Sites.Manage.All、Sites.FullControl.All
HTTP 要求
POST /sites/{site-id}/contentTypes
名前
説明
Authorization
ベアラー {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"
}
}