0

I normally use ClientContext to connect to SharePoint and use SiteUserInfoList to retrieve the list of SharePoint users. (I need to copy the data into an SQL Server database.) Disappointingly, this does not return all users in SharePoint. Specifically I am missing users that originate from another company; most likely there's some kind of security setting that prevents my user from seeing their data.

However, when I retrieve one of the lists I require, "Applications", I do get entries where these missing users are referenced, e.g. one of them is a DTSupplyAccountable of an Application. I only get a SharePoint ID, e.g. 265, and since I don't have a user with that ID I lack vital data about this Application.

Our SharePoint support recommended that I use the REST API instead to retrieve the data I need. Since there is no budget (or time) to rewrite the entire application, I've decided to use the REST API only to "plug the holes".

I was pleased to discover that calling _api/Web/SiteUsers gives me a far more complete list than SiteUserInfoList (see above). Yet this solution is imperfect: the resulting dataset lacks several properties I need:

  • FirstName
  • LastName
  • Department

Admittedly, I can retrieve these by calling _api/web/lists/GetByTitle('Applications')/items(7)?$select=DTSupplyAccountable/Id,DTSupplyAccountable/FirstName,DTSupplyAccountable/LastName,DTSupplyAccountable/Department,DTSupplyAccountable/Title,*&$expand= DTSupplyAccountable, but considering that I need to do this for dozens of users and considering the "inelegance" of this solution, I would much rather find another way to do this.

Is there any possibility that I can add parameters to SiteUsers to retrieve the missing properties?

4
  • Do you want to get all users who are added to a particular site collection or all user in your farm?
    – Unnie
    Sep 16, 2016 at 11:52
  • Preferably all users. Right now the issue is with the list Applications, but that is a starting point where other data links to, so ideally I would get all of the relevant properties of all of the users.
    – BCdotWEB
    Sep 16, 2016 at 11:53
  • How are the other company users added to the site? Directly or through any AD group?
    – Unnie
    Sep 16, 2016 at 12:03
  • @Unnie I don't know. SharePoint devs are a different department. I'm just importing data into a SQL Server table.
    – BCdotWEB
    Sep 16, 2016 at 12:21

1 Answer 1

0

Endpoint http://siteurl/_api/web/siteusers will return you all users who are added to that site,But it will not give you extra properties of the users like Department. SiteUserInfoList will have only those users who are added directly into the site and not through any AD group.

Alternately after getting list of users from SiteUsers you can query user profile for each user to get their additional properties. See this blog on retrieving properties from user profile.

2
  • I have seen that blog post, but I can't get it to work. User with ID 265 has <d:LoginName>i:0#.w|msnet\qqz7500</d:LoginName> but /_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0#.w|msnet\qqz7500' does not work.
    – BCdotWEB
    Sep 16, 2016 at 12:30
  • 1
    Don't user i:0#.w|. Just use domain\user (accountName=@v,propertyName='LastName')?@v='domain\username'
    – MickB
    Sep 16, 2016 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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