For SharePoint Online connector We used following steps to fetch all sites:
Step 1: Created Add-in on SharePoint instance with following permission xml
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl"/>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>
</AppPermissionRequests>
Step 2: Used below API to get all sites and subsites
https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site' &rowlimit=100
Issue we are facing –
sites, sub sites along with user’s
personal site(One drive)
, while we need all sites and sub sites
only.We referred following links:
You should add a path filter in the endpoint.
Normal site collections have a path like https://tenant.sharepoint.com
whereas personal (One Drive) site collections have path like https://tenant-my.sharepoint.com/personal/*
.
So, modify your endpoint as below:
https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site
Path:"https://<site_name>.sharepoint.com/*"'&rowlimit=500
This will only return site collections starting with https://<site_name>.sharepoint.com
path and will exclude the One Drive site collections which are on a different path.