You can access the contenttypes
REST API at <<yoursiteurl>>/_api/web/contenttypes
. or for list-/library- level content types: <<yoursiteurl>>/_api/web/lists/getbytitle('teamlist')/contenttypes
If you are attempting to create a new ContentType, make sure you specify the Id as defined sub-object in your POST
Body.
{
'__metadata': {'type': 'SP.ContentType'},
'Description': 'TestDesc',
'Name': 'ContentType New',
'Group': 'Custom Group',
'Id':{
'__metadata':{
'type':'SP.ContentTypeId'
},
'StringValue':'0x01234567890'
}
}
If you are updating an existing content type, perform your PATCH
or MERGE
with the ContentTypeID specified in the URI, such as:
<<yoursiteurl>>_api/web/contenttypes('0x01234567890')
To make the content type "Visible", set Hidden
to false
, to Hide it, set Hidden
to true
:
{
'__metadata': {'type': 'SP.ContentType'},
'Hidden': false,
}
To set the Content Type Order, you have to use the uniqueContentTypeOrder
method on the Folder
object API (note, this is an operation on the folder, not on the List. While you can call uniqueContentTypeOrder
on the List object, it is read-only on that object and will not accept any updates.
Good: <<yoursiteurl>>_api/web/GetFolderByServerRelativeUrl('/sites/ati-poc/Lists/TeamList')/uniqueContentTypeOrder
Bad (read-only): <<yoursiteurl>>_api/web/lists/getbytitle('TeamList')/rootfolder/uniqueContentTypeOrder
{
"__metadata":{"type":"Collection(SP.ContentTypeId)"},
"results":[
{"StringValue":"0x01060095AA05C7EF742C4DB3F474F3C5212ACD"},
{"StringValue":"0x0100873141339207DB4DA9397A3866FB9F1D"}
]
}
Be sure when updating to specify your content-type with odata=verbose
and appropriate if-match
and x-http-method
:
headers = {
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json; odata=verbose",
"X-RequestDigest": <<DigestValue>>,
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
}