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

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.

SharePoint deveopment training course

Below is the HTML Code:


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


<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 endpoint. 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=””></script>


$(function () {

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




function getAllLists() {

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


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 />’;




function onQueryFailed() {




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.

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)


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

View all posts by Bijay Kumar →