0

How can i manage Content Type in SharePoint List using REST API, it's look like a very wide question, isn't it ? well what i'm looking for exactly is:

  1. How to change content type visibility option to hidden
  2. How to reorder content type

ps: All that using the REST API

0

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"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.