In the modern UI, SharePoint “Site Contents” page contains two tabs. Each tab shows the apps present in the SharePoint site.

Each tab sends a separate REST API request to get the respective data from the SharePoint.

SharePoint

Contents / App Tiles

Below is the sample JavaScript code to get the lists of available Lists, Librarie, and Apps from the site.

  1. <script src="/SiteAssets/js/jquery.min.js"></script>
  2. <div id="outputInfo"></div>
  3. <script type="text/javascript">
  4. $(document).ready(function() {
  5. jQuery.ajax({
  6. url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/AppTiles",
  7. method: "GET",
  8. headers: {
  9. "Accept": "application/json; odata=verbose"
  10. },
  11. success: function(data) {
  12. var appTiles = data.d.results;
  13. console.log(appTiles);
  14. var tempValue = "<h2>Site Contents</h2><br/>";
  15. appTiles.forEach(function(app) {
  16. tempValue += app.Title + " ( " + app.AppId + " )<br/>";
  17. });
  18. $("#outputInfo").html(tempValue);
  19. },
  20. error: function(data) {
  21. console.log(data);
  22. }
  23. });
  24. })
  25. </script>

Output

SharePoint

Subsites

Below is sample JavaScript code to get the subsites for the current user using SharePoint REST API.

  1. <script src="/SiteAssets/js/jquery.min.js"></script>
  2. <div id="outputInfo"></div>
  3. <script type="text/javascript">
  4. $(document).ready(function() {
  5. jQuery.ajax({
  6. url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetSubwebsFilteredForCurrentUser(nWebTemplateFilter=-1)?$filter=WebTemplate ne 'APP'",
  7. method: "GET",
  8. headers: {
  9. "Accept": "application/json; odata=verbose"
  10. },
  11. success: function(data) {
  12. var subSites = data.d.results;
  13. console.log(subSites);
  14. var tempValue = "<h2>Sub sites</h2><br/>";
  15. subSites.forEach(function(site) {
  16. tempValue += site.Title + "( " + site.Id + " )<br/>";
  17. });
  18. $("#outputInfo").html(tempValue);
  19. },
  20. error: function(data) {
  21. console.log(data);
  22. }
  23. });
  24. })
  25. </script>

Output

SharePoint