How to retrieve all lists and libraries using Rest API in SharePoint online Office 365 or SharePoint 2013?

Rest API SharePoint 2013 get all lists
InfoPath alternatives for form designing SharePoint

Here we will discuss how we can retrieve all lists and libraries in SharePoint Online Office 365 using Rest API. The same code will work for SharePoint 2016 and SharePoint 2013 also.

Here we will take a button and on click of the button we will display all lists. Both the html code and the rest api code we will put inside a script editor web part which we will add inside a web part page. If you want to know how to use a script editor web part then you can check out this article and also if you want to know how to create web part page in SharePoint 2013, you can follow this article.

Below is the HTML Code:

<div>

<input type=”button” id=”btnSubmit” value=”Get All Lists” />

</div>

<div id=”divResults”></div>

<div id=”divAllLists”></div>

Rest API Code:

Here we have first given the jQuery reference. If you are new to jQuery you can check out this article to know Load the Data in JQuery DataTable from SharePoint 2013 List using REST API.

Here also we have used _spPageContextInfo.webAbsoluteUrl to get the absolute url of the site which we have used in the Rest end point. You can check out _spPageContextInfo javascript or jquery variable in SharePoint 2013 for more information how we can use _spPageContextInfo.

Then in onQuerySucceeded method we are retrive all the lists in for each loop. And we are binding the data into the <div id=”divAllLists”></div>

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>

<script>

$(function () {

$(“#btnSubmit”).on(“click”, function () {

getAllLists();

});

});

function getAllLists() {

var fullUrl = _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists”;

$.ajax({

url: fullUrl,

type: “GET”,

headers: {

“accept”: “application/json;odata=verbose”,

“content-type”: “application/json;odata=verbose”,

},

success: onQuerySucceeded,

error: onQueryFailed

});

}

function onQuerySucceeded(data) {

var listItemInfo = ”;

$.each(data.d.results, function (key, value) {

listItemInfo += ‘Title: ‘ + value.Title + ‘<br />’;

});

$(“#divAllLists”).html(listItemInfo);

}

function onQueryFailed() {

alert(‘Error!’);

}

</script>

Once you Save the code and click on the button, it will display all the lists.

Rest API SharePoint 2013 get all lists
Rest API SharePoint 2013 get all lists

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

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 →

Leave a Reply