I am trying to add document set content type from site collection to a library, but I am failing to do that.
Please help me to solve this issue. I am trying to use React and SPFx for SharePoint Online Modern site.
AddContentTypeToList=()=>
{
let ctEndpointUrl = `${this.props.context.pageContext.web.absoluteUrl}/_api/web/lists/getbytitle('${this.props.list}')/ContentTypes/AddAvailableContentType`;
let listUrl = `${this.props.context.pageContext.web.absoluteUrl}/${this.props.list}`;
let options : ISPHttpClientOptions= {
method: "POST",
body: JSON.stringify(
{ 'Title' : "Test New CT" , 'Path' : listUrl }),
headers: {
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json;odata=verbose',
'odata-version': '',
type: "POST",
data: JSON.stringify({
"contentTypeId": "0x0120D52000B6B95AFB1E9F5444905DA0AFE9C8F2CF0014BD370B726AB045A140BBF6DA440933"
})
}
};
this.props.context.spHttpClient.post(listUrl,
SPHttpClient.configurations.v1, options).then((d:SPHttpClientResponse) => {
d.json().then(res => {
// success
alert("CT Created");
console.log(res);
})
}).catch(e => {
// error
console.log(e);
});
}