1

We are using people picker (jQuery autocomplete) in a SharePoint Provider hosted app for binding the data of AD users.

We are using predefined web service Interface (ClientPeoplePickerWebServiceInterface) from SharePoint.

In that we are getting only login name,email id, display name etc. but we are not getting user id. We require user id to insert the data into list (people and group field) through REST API.

When we are using the below code we are getting user id using login name(i:0#.w|vf-root\empadmin). It is working to get only SharePoint group users, but it is not working for all users who are in AD or user profile users.

Please help us to get user id or to insert login name (with out using user id) into people and group field.

/_api/web/siteusers/getbyloginname(@v)?@v='i%3A0%23.w%7Cvf-root\empadmin'

Update:

  • We are unable to use var context = new SP.ClientContext.get_current(); in provider hosted app.
  • We are calling ClientPeoplePickerWebServiceInterface through web method.
  • Using "/_vti_bin/ListData.svc/UserInformationList? $select=Id,Name&$filter=substringof('" + searchKey + "',Name)"; we are only getting site users. We need user ids from user profile
  • Also, is there any possibility to insert user(people and group field) using login name i:0#.w|vf-root\empadmin through rest api (without user id)?
1
  • UserId is fetched from the user in Site user information list. The user needs to have an entry in that list to get the UserId value
    – Unnie
    Commented Oct 27, 2015 at 8:52

1 Answer 1

5

I have below solution to get UserId from Login Name using REST API.

http://<site url>/_api/web/sitegroups(<group id>)/users(@v)?@v='<login name>'
http://<site url>/_api/web/siteusers(@v)?@v='<login name>'

here @v have different type of value like

1) i:0#.f|membership|[email protected]

…/users(@v)?@v='i%3A0%23.f%7Cmembership%7Cuser%40domain.onmicrosoft.com'

2) i:0#.w|domain\user

…/users(@v)?@v='i%3A0%23.w%7Cdomain\user'

3) i:05:t|adfs with roles|[email protected]

…/users(@v)?@v='i%3A05%3At%7Cadfs+with+roles%7Cuser%40domain.com'

Note: keep in mind that while getting user information from Login name first encode claim token and then merge it with login name and then pass it with single quote

For more information see the GetByLoginName method on MSDN.

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.