Create or Update list using rest api in SharePoint 2013/2016/Online

How to create SharePoint 2013 list using REST API?

This SharePoint rest API tutorial explains, how to create a list using Rest API in SharePoint 2013/2016 or SharePoint Online. We will also discuss how to update SharePoint 2013 list title using REST API?

REST API is a very good client side approach to do client side operation in SharePoint.

SharePoint deveopment training course

Create list using rest api in SharePoint Online/2013/2016

Below is the full code Rest API code to create a SharePoint list. The code we can add inside a Script editor web part or content editor web part in SharePoint.

<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/lists";
$.ajax({
url: requestUri,
type: "POST",
data:JSON.stringify({'__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true,'BaseTemplate': 100, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'My Test List REST' }),
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},

success: onSuccess,
error: onError
});
function onSuccess(data) {
alert(data+ ' List Created');
}

function onError(error) {
alert(JSON.stringify(error));
}
});
});
</script>

<input type="button" id="btnClick" value="Click to Create List"/>

Once the list has been created, you can see from the site content which will look like below:

create list using rest api in sharepoint
create list using rest api in sharepoint

Update list title using Rest API in SharePoint Online/2013/2016

Now, we will see how we can update list title using rest api in SharePoint 2013/2016.

Below Rest API code will help to update list title using rest api, which we can add inside a script editor web part or in a content editor web part in a web part page in SharePoint.

<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/lists/GetByTitle('My Test List REST')";
$.ajax({
url: requestUri,
type: "POST",
data:JSON.stringify({'__metadata': { 'type': 'SP.List' }, 'Title': 'My Test List REST-Updated' }),
headers: {
"X-HTTP-Method":"MERGE",
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val(),
"IF-MATCH": "*"
},

success: onSuccess,
error: onError
});
function onSuccess(data) {
alert(data+ ' List Title Updated');
}

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

</script>

<input type="button" id="btnClick" value="Update List Title"/>

Once you click on Update List Title, it will update the list title like below:

update list title using rest api in sharepoint online
update list title using rest api in sharepoint online

You may like following SharePoint Rest API tutorials:

Hope this SharePoint tutorial helps to create a list using rest api in SharePoint 2013/2016/Online. We also saw how to update a list title using rest api in SharePoint Online or SharePoint 2013/2016.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

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 →