I have a site with 150+ libraries that are tied to a business process. Each has the default view configuration from the template I used. Now the business process is evolving and users want to see additional fields in the default view. I was able to add the necessary columns via content type, no problem. Now I need to change the default view (all have the same name) to assist users in sorting and filtering files.
In the past I have use REST to add fields, change field names, etc... However, I can't seem to change the view settings. I have tried using a workflow and javascipt but I keep getting "Bad Request" no matter what I try.
I followed the MSDN directions here: https://msdn.microsoft.com/EN-US/library/office/dn531433.aspx#bk_View
As well as directions on StackOverflow on how to get the X-RequestDigest value. Which is working as expected.
Here is the error I'm getting (shortened here):
"A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected."
and
"status":400,"statusText":"Bad Request"
Here is the script I'm using.
(function () {
var payload = "{'__metadata': {'type': 'SP.View'}, 'Title': 'NEW-TITLE'}";
var xRequestDigest = $("#__REQUESTDIGEST").val();
console.log(payload);
console.log(xRequestDigest);
$.ajax({
url: "WEBSITE-URL/_api/web/lists/getbytitle('LIBRARY-NAME')/views/getbytitle('VIEW-NAME')",
method: "POST",
body: payload,
headers: {
"content-type": "application/json;odata=verbose",
"X-Requestdigest": xRequestDigest,
"accept": "application/json; odata=verbose",
"X-HTTP-Method": "MERGE"
},
success: printInfo,
error: logError
});
})()
function printInfo() {
console.log('View Updated');
}
function logError(error) {
console.log(JSON.stringify(error));
}