如何使用REST API创建ID为的站点内容类型 [英] How to create site content type with id using REST API

查看:10
本文介绍了如何使用REST API创建ID为的站点内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用REST API创建新的内容类型,它将是现有内容类型-工作流任务(SharePoint 2013)的子级。 因此,当我创建请求时,我会将父内容类型ID包括在新ID中。

我已尝试以下代码。

const api = '/_api/web/contenttypes';

const requestBody = {
        '__metadata':   {
            'type': 'SP.ContentType',
        },
        'Description': 'This is content type',
        'Name': 'TestContentType',
        'Group': 'TestContentTypeGroup',
        'Id': {
               '__metadata':   {
                'type': 'SP.ContentTypeId'                            
                },          
            'StringValue': '0x0108003365C4474CAE8C42BCE396314E88E51F000x010056401AE39A088645AD0597364A428033'             
        }
    };

const requestHeaders = {
    'accept': 'application/json;odata=verbose',
    'content-type': 'application/json;odata=verbose',
    'X-RequestDigest': <digestValue>
};

const requestData = JSON.stringify(requestBody);

var executor = new SP.RequestExecutor(<AppWebUrl>);
executor..executeAsync({
        url: '<BaseUrl>' + api,
        method: 'POST',
        body: requestData,
        headers: requestHeaders,
        success: res => {
            console.log(res);                 
        },
        error: error => {
            console.log(error);
        }
    });

它确实创建了新的内容类型TestContent Type,但它继承自Item内容类型,并且它没有我在请求中提供的ID。它随机生成任何ID。

有人能帮忙吗?

推荐答案

这实际上是rest API中的错误...

以下是为PnP JS库提交的一个问题的链接,其中添加内容类型的实现方式与您所做的相同:https://github.com/pnp/pnpjs/issues/457

帕特里克·罗杰斯也向Microsoft提交了一个问题以解决它:https://github.com/SharePoint/sp-dev-docs/issues/3276

这意味着,遗憾的是,目前还没有使用REST实现这一点的方法。 您所能做的就是提升问题的知名度,并希望它能很快得到解决。

这篇关于如何使用REST API创建ID为的站点内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆