I have spent two days trying to create a page with a specific Content Type in Pages list using REST API. It goes into error handler and returns "{"readyState":0,"responseText":"","status":0,"statusText":"error"}"
The content type contains several custom site columns, one of them is Taxonomy Field (myCategory). when I run following query in the browser I can see the custom properties as well.
http://publishsite/subsite1/_api/lists/getbytitle('Pages')/items
However when I run this JavaScript code to create a page it give me above error.
var url = _spPageContextInfo.webAbsoluteUrl + "_api/web/lists/GetByTitle('Pages')/items";
var requestHeaders = {
"accept": "application/json;odata=verbose",
"content-type":"application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
var pageData = {
"__metadata": { "type": "SP.Data.PagesItem" },
"Title": "title1",
"MyNewsText": "this is test news",
"MyNewsPuff": true,
"MyCategory": "cat1|559d4cf3-d230-4052-ab64-09211656e8f3",
"ContentTypeId": "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900F1B3E07D9EBC45268BEDFAEBE1AAF9D50076E9E8FCF8CDAC46817958CF4288E0BF"
};
var requestBody = JSON.stringify(pageData);
$.ajax({
url: url,
method: "POST",
body: requestBody,
headers: requestHeaders,
success: function (data) {
alert("created");
},
error: function (xhr, textStatus, errorThrown) {
alert("failed=" + JSON.stringify(xhr));
}
});