By a Rest query I consult
.../_api/web/siteusers to obtain the ID of all users and then I consult UserProfile to obtain more information about each user. But sometimes there are users does not exist in SiteUsers but if they exist in UserProfile. How do I do those users appear in SiteUsers? Why does this problem happen?
By a Rest query I consult
Users are added to User Profiles when then are imported from Active Directory, so you will generally find all users there.
Users are added to a Site Collection's site users collection when:
They have been granted explicit permissions to the a site in the Site Collection.
They are a Site Collection Administrator or a Site Owner.
- They are members of an AD group, AND, have also visited the site at least once.
- They are members of a SharePoint Group in that Site Collection.
Be aware that there are three collections of users for each web site (SPWeb).
There are three user collections available from SPWeb: .Users, .AllUsers and .SiteUsers.
- web.Users: SPWeb.Users gets the collection of user objects that are explicitly assigned permissions in the Web site. It will not return users who have access through a group.
- web.AllUsers: SPWeb.AllUsers gets the collection of user objects that represents all users who are either members of the site collection or who have browsed to the site as authenticated members of a domain group in the site.
- web.SiteUsers: SPWeb.SiteUsers gets the collection of all users that belong to the site collection.
In the example below showing users in the SPWeb collections:
- Jane has was assigned directly to a permission level, so she is in Users, AllUsers and SiteUsers
- Luis is a Site Collection Administrator from the parent of this site and he has never visited this site, so he is in SiteUsers. If he visits the site he will then be in AllUsers
- Sam is the Owner of this site, so he is in AllUsers and SiteUsers
- Richard is member of the Members group, so he is in AllUsers, SiteUsers
Jesse is in the domain group "MAXSP2007\IT", but has never visited the site and does not show up in any user collection.
.SiteUsers: NT AUTHORITY\local service
Group: Sub Site Visitor: MAXSP2007\IT
Group: Sub Site Members: MAXSP2007\richardm
Group: Sub Site Owners: MAXSP2007\samc
in SharePoint REST API
/_api/web/siteusers endpoint only provides the list of users has permission on current web. Since, you are fetching the users using Site Permissions, there are high chances that all users doesn't have permission.
Also in SharePoint REST API endpoint for
user profile, there is no direct way to fetch all the users. But you can use Search REST API endpoint to query against UserProfile and get the list of users.