title: SharePoint Get all sites and all sub sites using SharePoint online REST API
body: <p>For SharePoint Online connector We used following steps to fetch all sites:</p>
  
  <p><strong>Step 1:</strong> Created Add-in on SharePoint instance with following permission xml</p>
  
  <pre><code>&lt;AppPermissionRequests&gt;
          &lt;AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl"/&gt;
          &lt;AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/&gt;
  &lt;/AppPermissionRequests&gt;
  </code></pre>
  
  <p><strong>Step 2:</strong>     Used below API to get all sites and subsites</p>
  
  <pre><code>https://&lt;site_name&gt;.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site' &amp;rowlimit=100
  </code></pre>
  
  <p><strong>Issue we are facing</strong> – </p>
  
  <ol>
  <li>Above endpoint is returning all <code>sites, sub sites along with user’s
  personal site(One drive)</code>, while we need all <code>sites and sub sites</code>
  only.</li>
  <li>Please suggest <strong>minimal required permission to read all site, all subsite, all folders and files metadata</strong></li>
  </ol>
  
  <p>We referred following links:</p>
  
  <ul>
  <li><a href="http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/" rel="nofollow noreferrer">http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/</a></li>
  <li><a href="https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint</a></li>
  <li><a href="https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service</a></li>
  </ul>