1

Does anyone know how to fetch all site collections from my SharePoint admin center by using rest api / search api / graph api?

I have tired using search and graph api :

let query = SearchQueryBuilder("contentclass:sts_site").rowLimit(500).selectProperties("Title", "SiteId", "WebId", "Path", "SPWebUrl"); sp.search(query).then((res) => { let results = res.PrimarySearchResults; console.log(results); });

Ref for graph api

Ref for grpah api

I am not getting all the site collections, in SharePoint admin center has 105 sites but I am getting only 55 sites.

Even the user has site admin permission. eg : A user (login user) can see the XXX site but not to the B user (login user) who has site admin permission.

SharePoint admin center active sites counts

Could you help me?

3
  • Are you Global administrator/SharePoint (tenant) administrator? Sep 2 '21 at 11:12
  • tenant administrator.
    – Paul
    Sep 2 '21 at 12:38
  • Try using endpoint given in my answer below. let me know if it works for you. Sep 2 '21 at 12:53
1

You can get all site collections from SharePoint online admin center using REST API endpoint like:

https://<tenant>-admin.sharepoint.com/_api/web/lists/getbytitle('DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS')/items?$select=Title,SiteUrl
3
  • 1
    its working ganesh, thanks alot. and if the user does not have tenant admin permission? what is the solution for that? i am unaware whether my client have admin permission. could you help me!
    – Paul
    Sep 2 '21 at 13:52
  • If user does not have access on SP admin site, they will not able to fetch site collections using this endpoint. I will check if there is any workaround for this & update the thread. But it is recommended to have SP admin permissions when accessing such information from admin site. Sep 2 '21 at 15:12
  • thanks @Ganesh and upvoted, if only admin user can get all site collections, then how come partially getting site collections using this code : let query = SearchQueryBuilder("contentclass:sts_site").rowLimit(500).selectProperties("Title", "SiteId", "WebId", "Path", "SPWebUrl"); sp.search(query).then((res) => { let results = res.PrimarySearchResults; }); i have issue like one of the site collection named UAT is visible to one user, but not to the other user who has same permission for both of them.? could you know why ? even in graph api getting same results same like search api.
    – Paul
    Sep 3 '21 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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