Get All Sites and Sub Sites using REST API

This post will explain you how to Get All Sites and Sub Sites using REST Api in SharePoint Online

In order to get the list of sub sites from a site we need to call the below URL:

Now to get the entire site structure we will need to loop every site to see if there are any sub sites present.

Below is the code I have used.

//The First Ajax is to get the Root Site Title and the Relative URL

// The Second AJAX is to get all the sub sites under the Root Site
// This is a Recursive Function to loop through the sub sites and check for more sub sites
Reference link :

This article has 3 comments

  1. Juan sebastian Illera duque



    Hello, great script, there is a way i can use a same approachs but for a site collection that have subsites with subsites?

  2. Pingback: Save SharePoint People search result as csv file using javascript | SharePoint Q&A

Leave a Comment