Microsoft 365: How to retrieve administrators of all site collections in SharePoint Framework (SPFx) component using sharepoint REST API

Hi All,

Greetings for the day!!!

I am compiling frequently used SharePoint REST APIs. In this series of articles today we are listing all site collections and respective Admins.


What is Rest API?

A Representational State Transfer (REST) API is a type of web service that allows different software applications to communicate with each other over the internet. It follows a set of architectural principles and constraints, using standard HTTP methods like GET, POST, and PUT to perform various operations on data. REST APIs are widely used for retrieving, creating, updating, and deleting data in a simple and consistent manner, making them a fundamental technology for web-based interactions between applications.

Let’s look into SPFx Component :

Step 1 :

This code imports the necessary modules for creating a SharePoint Framework web part.

The ‘react‘ import is for using React for building the user interface, Executes the SharePoint Search query using the SPHttpClient class, SPHttpClientResponse represents the response from a SharePoint HTTP request. WebPartContext is for accessing the web part’s context, including SharePoint-specific information.

fig : Imports the necessary modules

Step 2 :

We have defined variables in typescript.

fig : Variable declaration in typescript

Step 3 :

Initializing the state

fig : State initialization

Step 4 :

We are using the SPHttpClient to make a GET request to the SharePoint REST API to get a list of all site collections in the tenant. The provided API is a SharePoint REST API query used to search for site collections. It searches for site collections based on the condition “contentclass:STS_Site,” and it specifies the properties “Title” and “Path” to be retrieved for each site collection in the search results.

fig : Fetching site collections

Step 5 :

We are using the SPHttpClient to make a GET request to the SharePoint REST API to fetch data for each site collection in the tenant. It filters the results to only include users with the property “IsSiteAdmin” set to true, which represents users with administrative privileges for the site.

fig : Fetching Admins

Step 6 :

Let’s iterate through the list of site collections and admins in the state and renders a list item for each site collection.

fig : Site collection and Admins Name rendering

Build a component using gulp build and gulp bundle for bundling files and for testing purpose I am using gulp serve so it opens the workbench.aspx.

fig : Gulp build for project compilation
fig : Bundling files using gulp bundle
fig : Running gulp serve for local development.

and after successfully execution of above command, component will show the following result.

fig : Site collection and admins output

I hope this article will help you to know about SharePoint REST API , SharePoint Framework (SPFx) component and

how to get all site collections and admins in tenant using SharePoint Rest API.

References :

Also get my article updates on my social media handles. 

LinkedIn –

Twitter –

Have a wonderful day.  

Thanks for reading. 

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: