2

So I use

http://mysite.com/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(AccountName=@v,propertyName=%27empID%27)?@v='someaccountname'

This works fine for me as I have the correct AccountName for any user.

But what if I have property name EMPID =123456 (see image of xml below for properties) and I want to fetch other userprofile properties like EMPNAME (also in the image below).

something that looks like http://mysite.com/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(propertyName=%27empID%27@v)?@v='123456'

which would return 'firstnameofemployee' matching the EMPID=123456

Essentially not use AccountName but use other Userprofileproperties. Is there a way to do that? I have been looking for a solution but all I get is examples of api's with AccountName only. Which makes me wonder if there is no other way to do this.

If you would like to know xml with properties EMPID and EMPNAME

enter image description here

1
  • 2
    That's not possible as this API expects accountname. To filter on the custom property, you need to use the search REST API Apr 16, 2020 at 6:53

1 Answer 1

1

It is possible, but you need to use different approach.

You can use search REST APIs to filter users by custom profile property. Normally default profile properties, like AccountName etc. are mapped to corresponding managed properties in search.

Since you are using custom profile properties, you need to make sure that this mapping exists in the search schema or create it if it's missing.

After that, you can execute the search query to find all people with your custom profile property, in your case EmpId.

For example following query searches all people by EmpId assuming that EmpId exists as a managed property and is populated:

https://<tenant>.sharepoint.com/sites/dev/_api/search/query?
querytext='EmpId:"123456"'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'

the GUID B09A7990-05EA-4AF9-81EF-EDFAB16C4E31 is reference to people search results and common in SharePoint.

After executing this HTTP request, you will get the result.

Do note however that in SP Online, populating of the managed properties can take upto 1 week.

To map a custom user profile property to a managed property, can you can follow this link.

It is a lengthy and time consuming process, but unfortunately there is no alternative at the moment for this.

Also, to do this mapping process, you need to be a SharePoint admin or have access to the admin center

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.