contentType:addCopyFromContentTypeHub
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
将已发布内容类型的副本从内容类型中心添加或同步到目标网站或列表。
此方法是内容类型发布更改的一部分,可优化已发布内容类型到网站和列表的同步,从而有效地从"推送无处不在"切换到"根据需要拉取"方法。 此方法允许用户将内容类型直接从内容类型中心拉取到站点或列表。 有关详细信息,请参阅 getCompatibleHubContentTypes 和博客文章 Syntex Product Updates – August 2021。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Sites.Manage.All、Sites.FullControl.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
Sites.Manage.All、Sites.FullControl.All |
HTTP 请求
POST /sites/{siteId}/lists/{listId}/contentTypes/addCopyFromContentTypeHub
POST /sites/{siteId}/contentTypes/addCopyFromContentTypeHub
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供参数的 JSON 表示形式。
下表显示了可用于此操作的参数。
| 参数 |
类型 |
说明 |
| contentTypeId |
字符串 |
要添加到目标网站或列表的内容类型集线器中的内容类型的 ID。 |
响应
如果成功,此操作将在 200 OK 响应正文中返回 响应代码和 contentType 202 Accepted 对象(如果内容类型是同步添加的)或响应代码(如果内容类型将异步同步)。 该响应还将包含 Location 一个标头,其中包含为处理复制/同步而创建的 richLongRunningOperation 的位置。对于异步操作,最多可能需要 70 分钟才能同步或添加内容类型。
示例
示例 1:同步拉取
请求
POST https://graph.microsoft.com/beta/sites/{siteId}/lists/{listId}/contentTypes/addCopyFromContentTypeHub
Content-Type: application/json
Content-length: 33
{
"contentTypeId": "0x0101"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var contentTypeId = "String";
await graphClient.Sites["{site-id}"].Lists["{list-id}"].ContentTypes
.AddCopyFromContentTypeHub(contentTypeId)
.Request()
.PostAsync();
const options = {
authProvider,
};
const client = Client.init(options);
const contentType = {
contentTypeId: 'String'
};
await client.api('/sites/{siteId}/lists/{listId}/contentTypes/addCopyFromContentTypeHub')
.version('beta')
.post(contentType);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/sites/{siteId}/lists/{listId}/contentTypes/addCopyFromContentTypeHub"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSString *contentTypeId = @"String";
payloadDictionary[@"contentTypeId"] = contentTypeId;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
String contentTypeId = "String";
graphClient.sites("{siteId}").lists("{listId}").contentTypes()
.addCopyFromContentTypeHub(ContentTypeAddCopyFromContentTypeHubParameterSet
.newBuilder()
.withContentTypeId(contentTypeId)
.build())
.buildRequest()
.post();
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewContentTypeIdRequestBody()
contentTypeId := "String"
requestBody.SetContentTypeId(&contentTypeId)
siteId := "site-id"
listId := "list-id"
result, err := graphClient.SitesById(&siteId).ListsById(&listId).ContentTypes().AddCopyFromContentTypeHub(site-id, list-id).Post(requestBody)
Import-Module Microsoft.Graph.Sites
$params = @{
ContentTypeId = "String"
}
Add-MgSiteListContentTypeCopyFromContentTypeHub -SiteId $siteId -ListId $listId -BodyParameter $params
响应
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.contentType",
"id": "0x0101",
"description": "Document content type",
"group": "Document Content Types",
"hidden": false,
"isBuiltIn": true,
"name": "Document"
}
示例 2:异步拉取
请求
POST https://graph.microsoft.com/beta/sites/{siteId}/lists/{listId}/contentTypes/addCopyFromContentTypeHub
Content-Type: application/json
Content-length: 33
{
"contentTypeId": "String"
}
响应
HTTP/1.1 202 Accepted
location: https://graph.microsoft.com/beta/sites/{siteId}/lists/{listId}/operations/{operationId}