Skip to main content

TechEnhance

Looking for someone to manage the backend tech in your business?

We’ve helped 100s of businesses in the in America and we got you too!

Table of Contents

Would you like to share this article?

REST API in SharePoint: 1 Best Way To Get All Users From Site

REST API in SharePoint

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.

Explore Our Complete Tech Series Archive
Contact Us Arrow Icon

The Method

<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.

Get in touch for a free consultation

Get in Touch Now!
Ankit Tayal
AUTHOR

Ankit Tayal

(Founder & CEO, Techenhance)

A journey that started with passion for Technology, also led Ankit towards mastery of Business. With 16+ years of experience in the IT industry working with organizations like Accenture and PwC he has gained mastery over the crafts of leadership, customer relationship management & business partnership. He dreams to build a world that has adapted tech with efficiency & confidence. To achieve his dream Ankit invests his days & nights into the growth of TechEnhance & its clients.

Related Blogs

Good move, automating your backend!
Good move, automating your backend!
Please enter your email to access the guide.