I am using the REST API to search through SharePoint using the call:


but I am also getting all the personal sites and links to OneDrive folders.

How can I exclude them from using this REST API search query for both SharePoint online and on-premise?

1 Answer 1


You can add a path filter in your REST API 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, you can modify your endpoint as below:

https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site Path:"https://<site_name>.sharepoint.com/*"'&rowlimit=1000

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.

  • It is still returning personal sites with the path https://<sitename>.sharepoint.com/portals/personal/<user name>
    – Lez
    Commented Jun 15, 2020 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.