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.

1 Answer 1

3

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": "[email protected]",
            "mobilePhone": null,
            "officeLocation": null,
            "preferredLanguage": null,
            "surname": null,
            "userPrincipalName": "[email protected]"
        }
    ]
}

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

1
  • 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
    Commented Oct 25, 2018 at 10:35

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.