Sharepoint 2013 REST add to document library with custom content type - JS

I'm on a project where I'm implementing a CRUD for a Sharepoint 2013 Document Library which includes two custom content types, the default one I'll call MyDoc which is derived from Document and another type I'll call MyDocSet which is derived from Document Set. I'm doing this with JS/jQuery.

I can't seem to figure out how to set the content type when creating a list item. I want to add an item of content type MyDocSet, but it always wants to assume the default content type.

Here is my unsuccessful attempt:

var executor = new SP.RequestExecutor(baseUrl); var bodyContent = JSON.stringify({ "__metadata": {"type": "SP.Data.LineJSubmitItem"}, //How to set content type ID? }); executor.executeAsync({ url: baseUrl + "/sites/linej/_api/web/lists/GetByTitle('LineJSubmit')/items", method: "POST", headers: { "Accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": formDigestValue, "content-length": bodyContent.length, }, body: bodyContent, success: function(data) { alert("success"); }, error: function(data, errorCode, errorMessage) { var jsonObject = JSON.parse(data.body); var errMsg = jsonObject.error.message.value; alert(errMsg); } });

-------------Problems Reply------------

With the SP.RequestExecutor you have to make sure the appweburl and hostweburl parameters are used properly. For example, I assume the 'baseUrl' value you are using is really the appweburl that you receive from SharePoint.

Additionally, you will need to append the target url (the hostweburl) to your URL string.

Though this deals with updates, it may be useful to see my post here.

Category:sharepoint 2013 Views:0 Time:2013-06-24

Related post

Copyright (C), All Rights Reserved.

processed in 0.086 (s). 11 q(s)