Rest API
How to update Document Set properties using REST API in SharePoint 2013

Update Document Set using REST API in SharePoint 2013

You can perform essential create, read, update, and delete (CRUD) operations by REST API in SharePoint 2013. The REST interface exposes all the SharePoint entities and services available in the other SharePoint client APIs. One advantage of using REST is that you don’t have to add references to any SharePoint libraries or client assemblies. Instead, you make HTTP requests to the appropriate endpoints to retrieve or update SharePoint entities, such as webs, lists, and list items.

<script src=”https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js” type=”text/javascript”></script>
<script>

function executeJson(url,method,additionalHeaders,payload)
{
if(method == “GET”) {
return $.ajax
({
url: url,
type: method,
headers: {
“accept”: “application/json;odata=verbose”,
},
success: function(data)
{
return data;
},
error: function(error)
{
alert(JSON.stringify(error));
}
});
}
if(method == “POST”) {
return $.ajax
({
url: url, // list item ID
type: method,
data: JSON.stringify(payload),
headers: {
“Accept”: “application/json;odata=verbose”,
“Content-Type”: “application/json;odata=verbose”,
“X-RequestDigest”: $(“#__REQUESTDIGEST”).val(),
“X-HTTP-Method”: “MERGE”,
“If-Match”: “*”
},
success: function(data, status, xhr)
{
},
error: function(xhr, status, error)
{
alert(JSON.stringify(error));
}
});
}
}

function renameFolder(webUrl,folderUrl,name)
{
var folderItemUrl = webUrl + “/_api/web/GetFolderByServerRelativeUrl(‘” + folderUrl + “‘)/ListItemAllFields”;
executeJson(folderItemUrl,”GET”).success(function(data){
UpdateValue(data,name)
});
}

function UpdateValue(data,name){
debugger;
var itemPayload = {};
itemPayload[‘__metadata’] = {‘type’: data.d[‘__metadata’][‘type’]};
itemPayload[‘Title’] = name;
var itemUrl = data.d[‘__metadata’][‘uri’];
var additionalHeaders = {};
additionalHeaders[“X-HTTP-Method”] = “MERGE”;
additionalHeaders[“If-Match”] = “*”;
console.log(itemPayload);
return executeJson(itemUrl,”POST”,additionalHeaders,itemPayload);
}

function Folder(){
renameFolder(“siteurl”,’pathtoDocumentSet’,’ValuetoChange’).done(function()
{
console.log(‘Folder has been renamed’);
})
.fail(
function(error){
console.log(JSON.stringify(error));
});
}

</script>

<button onclick=”Folder()”>Click me</button>

The above given code will help you to Update Document Set using REST API.

For any query Contact us or email us to [email protected]

About Us

We create experiences that change the way people interact with brands – and with each other

Newsletter