0

I know this has been asked several times but I haven't found a viable solution.

I am building a spfx webpart where I want to display every single user with name, title, email etc.

I am using the pnp-js library for this. When i try to access siteusers (as suggested in so many answers) i only get the ones that i have given permission.

I have given "Everyone" access to the site. I did try the following:

pnp.sp.web.siteUsers.get().then(result => {
   console.log(result);
});

But this only returns the groups and the users that i have added manual to the site.

How can I get info about every single user?

The search api is not an option because i would have to a make an HTTP call for each users to get username, email, title etc.

2

As far as I know there is no way to get all users using the REST API. When I've needed to do this I've instead used the Microsoft Graph.

https://graph.microsoft.com/v1.0/users

You will get a response back that looks something like this:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    "value": [
        {
            "id": "6e7b768e-07e2-4810-8459-485f84f8f204",
            "businessPhones": [],
            "displayName": "Conf Room Adams",
            "givenName": null,
            "jobTitle": null,
            "mail": "Adams@M365x214355.onmicrosoft.com",
            "mobilePhone": null,
            "officeLocation": null,
            "preferredLanguage": null,
            "surname": null,
            "userPrincipalName": "Adams@M365x214355.onmicrosoft.com"
        }
    ]
}

The documentation describing how to work with Users in the Microsoft Graph can be found here: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/users

  • Thanks. I had hoped that I shouldn't handle any authentication. Too bad they haven't integrated it more closely with Sharepoint Online. Seems like a pretty common requirement. – TietjeDK Oct 25 '18 at 10:35

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.