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.
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="https://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:
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="https://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:
You may like following SharePoint Rest API tutorials:
- Display custom alert message in SharePoint using REST API
- Create a Custom People Directory using REST API in SharePoint
- Retrieve and Display TASK status using REST API in SharePoint
- Create a Custom Calendar in SharePoint using Rest API and jQuery
- Display SharePoint list data in jQuery data table using Rest API
- Create Highcharts in SharePoint using Rest API
- Create SharePoint Quote of the day web part using Rest API and Bootstrap
- Display Task List data in a table using SharePoint REST API and filter by status column
- SharePoint 2013 Add Top Navigation Link to a Site Using REST API
- Create a custom User profile web part using SharePoint REST API and bootstrap
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.
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 SPGuides.com