1

I would like to change the Content Type of items in a SharePoint On-Line Document Library, using VBA and the REST API.

I would like to change existing Folders to a custom Content Type, derived from the 'Document Set' Content Type, and I would also like to change Files to a (different) custom Content Type, derived from the 'Document' Content Type.

Presently I am trying to change a Folder, and I am getting:-

Status : 400
StatusText : Bad Request
ResponseText (message) : The property 'ContentTypeID' does not exist on type 'SP.Data.DocSetTestItem'. Make sure to only use property names that are defined by the type.

Below is what I believe to be the relevant part of my code; Item ID 6 is presently a test 'Folder' and I wish to change it to my Custom Content Type (derived from 'Document Set'), which in the Library has the Content Type ID as shown in the code.

My Document Library is called DocSetTest

Const mconSzQt As String = """"
szURL = "https://[mysitename].sharepoint.com/DevTest/_api/web/lists/GetByTitle('DocSetTest')/items(6)"
szBody = "{ " & mconSzQt & "__metadata" & mconSzQt & ": { " & mconSzQt & "type" & mconSzQt & ": " & mconSzQt & "SP.Data.DocSetTestItem" & mconSzQt & " }, " & mconSzQt & "ContentTypeID" & mconSzQt & ": " & mconSzQt & "0x012000DEAAEAEC057AD24087800E42861958AA006264943C4C9D044C96EDFA5641272A46" & mconSzQt & " }"
With oHttp
    .Open "POST", szURL, False
    .setRequestHeader "accept", "application/atom+xml"
    .setRequestHeader "X-HTTP-Method", "MERGE"
    .setRequestHeader "IF-MATCH", "*"
    .setRequestHeader "Content-Type", "application/json;odata=verbose"
    .setRequestHeader "X-RequestDigest", mSzDigest
    .setRequestHeader "Content-Length", Len(szBody)
    .Send szBody

I have not, as yet, tried changing a File's Content Type this way. If I can't get it to work for a Folder, the whole exercise is a total loss.

Can anybody please offer advice, or advise the required corrections to the above code?

  • can you try it as ContentTypeId instead of ContentTypeID. Check lower case :) . Secondly, check this answer. I tried it and it works ! – Gautam Sheth Sep 10 '18 at 5:26
  • Thank you - such a simple thing to fix (if you know what to look for!). Please post your comment as an answer and I will accept it. I have tested on my test library, for both folder-> custom doc set, and standard 'document' to custom document. Both worked when correct text case was applied. – John7766 Sep 10 '18 at 14:54
1

As mentioned in comments, it needs to be ContentTypeId and not ContentTypeID where Id is in lowercase.

So modify your line of code as below:

szBody = "{ " & mconSzQt & "__metadata" & mconSzQt & ": { " & mconSzQt & "type" & mconSzQt & ": " & mconSzQt & "SP.Data.DocSetTestItem" & mconSzQt & " }, " & mconSzQt & "ContentTypeId" & mconSzQt & ": " & mconSzQt & "0x012000DEAAEAEC057AD24087800E42861958AA006264943C4C9D044C96EDFA5641272A46" & mconSzQt & " }"

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.