Is there any way to add a user as Site Collection Administrator in SharePoint Online Sites using Rest API or pnp js?. I am using SPFx react js webpart. I have code in c#, but I cannot use it in my SPFx webpart.


You can use the pnpjs library to add the site collection admin.

Firstly, you need to add the below import statement:

import { sp, WebEnsureUserResult, UserUpdateResult } from "@pnp/sp";

After that, you can use the code as below:

.then((d: WebEnsureUserResult) => {

        var id = d.data.Id;

        }).then((d:UserUpdateResult) =>{

            console.log("Successfully added admin");


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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