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.

1 Answer 1


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:

sp.web.ensureUser("[email protected]")
.then((d: WebEnsureUserResult) => {

        var id = d.data.Id;

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

            console.log("Successfully added admin");


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.