Welcome to an article on “How to get all SharePoint Lists using REST API in SharePoint Online and Office 365” where we will see the steps of creating an app using Napa Tool which will help us to view all the lists on our site using REST API.
- Open the “NAPA” Office 365 Development Tools through your SharePoint store.
- Click on Add New Project.
- It will ask you, what type of app do you want to build?
![add]()
- Select SharePoint Add-in and provide a name to your app and click on Create.
![add in]()
- You will see the screen below on the app.
![content]()
- Click on Default.aspx and paste the code below under the, “<asp:ContentContentPlaceHolderID="PlaceHolderMain" runat="server">”.
Code:
- <div>
- <p>
- <b>All Lists</b>
- <br />
- <select style="height:200px; width:200px" multiple="multiple" id="findlist"></select>
- </p>
- </div>
- Now on the navigation click on the App.js file and paste the code below removing the previous code completely.
Code:
- 'use strict';
- var hostweblink;
- var applink;
-
- $(document)
- .ready(function()
- {
- hostweblink = decodeURIComponent(
- getQueryStringval("SPHostUrl"));
- applink = decodeURIComponent(
- getQueryStringval("SPAppWebUrl"));
-
- varscriptlink = hostweblink + "/_layouts/15/";
- $.getScript(scriptlink + "SP.RequestExecutor.js", loadPage);
- });
-
- function getQueryStringval(paramToRetrieve)
- {
- var paramval = document.URL.split("?")[1].split("&");
- for (vari = 0; i < paramval.length; i = i + 1)
- {
- var param1 = paramval[i].split("=");
- if (param1[0] == paramToRetrieve) return param1[1];
- }
- }
-
- function loadPage()
- {
- getalllist();
- }
- function getalllist()
- {
- var play;
- play = new SP.RequestExecutor(applink);
- play.executeAsync({
- url: applink + "/_api/SP.AppContextSite(@target)/web/Lists?@target='" + hostweblink + "'",
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: getlistcompleted,
- error: getlistfailed
- });
- }
-
- functiongetlistcompleted(data)
- {
- varjsonobjectbody = JSON.parse(data.body);
- varfindlists = document.getElementById("findlist");
- if (findlists.hasChildNodes())
- {
- while (findlists.childNodes.length >= 1)
- {
- findlists.removeChild(findlists.firstChild);
- }
- }
- var results = jsonobjectbody.d.results;
- for (var i = 0; i < results.length; i++)
- {
- var selectOption = document.createElement("option");
- selectOption.value = results[i].Title;
- selectOption.innerText = results[i].Title;
- findlists.appendChild(selectOption);
- }
- }
-
- function getlistfailed(data, errorCode, errorMessage)
- {
- alert("Could not load the lists :" + errorMessage)
- }
- Click on the settings icon on the tool on the left.
![tool]()
- Under the properties, select Permissions and provide full control to the app on the Site Collection level.
![permission]()
- Click on the deploy button on the left and run the project.
![run]()
- Click on the launch button.
![launch]()
- Accept the trust and click on ‘Trust It’.
![trust it]()
- Your app will be deployed and open for you as per the following screenshot:
![get all list]()
- Your entire lists will load on your app on the page load of the app.
Here we saw today how to get all SharePoint Lists using REST API in SharePoint Online and Office 365. You will love your app. Keep reading and keep learning.
Read more articles on SharePoint: