4

I'd like to get all user profiles filtered by a specific property (department for instance) using REST. Is that possible? In my dreams:

_api/SP.UserProfiles.PeopleManager/GetUsersByProperty(MyProperty='X')

1 Answer 1

9

Yes, it is possible, but you need to use slightly different approach.

You can use search in order to filter users by profile property. Normally core profile properties are mapped to corresponding managed properties in search. If you are using custom profile properties, you need to make sure that this mappings exist or create it if it's missing.

Then you can run search query to find all people with profile property.
For example following query searches all people by acccount name mask:

https://mysp.sharepoint.com/sites/dev/_api/search/query?querytext='accountname:"*john*"'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'

this guid B09A7990-05EA-4AF9-81EF-EDFAB16C4E31 is reference people search results.
Later you need to parse search result, grab AccountName and then use rest to query particular user profile and extract properties.

A bit more samples and info here - Working with People Search and User Profiles

5
  • Thanks for reply! But the link above return no users. [code] <d:RowCount m:type="Edm.Int32">0</d:RowCount> <d:Table m:type="SP.SimpleDataTable"> <d:Rows/> </d:Table> <d:TotalRows m:type="Edm.Int32">0</d:TotalRows> [/code]
    – kolback
    Nov 9, 2016 at 15:03
  • Try to use * to query all users and see the properties - https://sp.sharepoint.com/sites/dev/_api/search/query?querytext='*"'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31' Nov 9, 2016 at 15:06
  • Then I can see AccoundName among other properties. But I cannot find any users at all. Noticed that this is working though: /_api/web/siteusers?$select=Id,Title,LoginName,Email&$filter=Title eq 'My Name'
    – kolback
    Nov 9, 2016 at 15:22
  • Does people search on your web site work? Try to open people search from UI to see. Nov 9, 2016 at 15:26
  • Hm, there is something else that is wrong here... Thanks for your help!
    – kolback
    Nov 10, 2016 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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