Rest API Create folder inside document library in SharePoint 2013 and Delete folder from Document library using Rest API

In this post, we will discuss how to create a folder inside the document library as well as how to delete the folder from the document library using the Rest API in SharePoint 2013.

Also you may like to see:
Create SharePoint 2013 group using Rest API and Update SharePoint Group Details using Rest API


Add user other than logged in user to SharePoint group using JavaScript object model

Switch from Classic to Claims Authentication in SharePoint 2010.

Create folder inside document library in SharePoint 2013:
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script>
$(function(){
$(“#btnClick”).click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/folders”;
$.ajax({
url: requestUri,
type: “POST”,
data:JSON.stringify({‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’: ‘Shared Documents/Folder1’}),
headers: {
“accept”:”application/json;odata=verbose”,
“content-type”: “application/json;odata=verbose”,
“X-RequestDigest”:$(“#_REQUESTDIGEST”).val()
},
success: onSuccess,
error: onError
});

function onSuccess(data) {
alert(‘Folder created successfully’);
}

function onError(error) {
alert(JSON.stringify(error));
}

});

});

</script>

<input type=”button” id=”btnClick” value=”Create Folder Inside Document Library”/>

Delete folder from Document library using Rest API SharePoint 2013:
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script>
$(function(){
$(“#btnClick”).click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/GetFolderByServerRelativeUrl(‘Shared Documents/Folder1’)”;
$.ajax({
url: requestUri,
type: “POST”,
headers: {
“X-HTTP-Method”:”DELETE”
},
success: onSuccess,
error: onError
});

function onSuccess(data) {
alert(‘Folder deleted successfully’);
}

function onError(error) {
alert(JSON.stringify(error));
}

});

});

</script>

<input type=”button” id=”btnClick” value=”Delete Folder From Document Library”/>

Check out Best Alternative to InfoPath -> Try Now

EnjoySharePoint YouTube Channel

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →
    • Hi Ravi,
      Could you please let me know if you are getting any specific error? Because the code works fine for me.