7

I'm trying to retrieve user people with rest api. But it does not work.

var getSpecificUserProperty = "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+encodeURIComponent('i:0#.f|membership|[email protected]')+"'";


 $.ajax({
  url: siteUrl + getSpecificUserProperty,
  type: "GET",
  headers: { "accept": "application/json;odata=verbose" },
  success: function(data, status){
    console.log(data.d.results);

 },
  error: function(err){
    console.log(err);
  }
});

Why doesn't this code work? What am i doing wrong?

1

2 Answers 2

5

May be you are missing encodeURIComponent()

URL should look like

/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+encodeURIComponent('i:0#.f|membership|[email protected]')+"'

PS: After applying encodeURIComponent() I got it working.

If you are using any REST client, then convert i:0#.f|membership|[email protected] into encodeURIComponent at first.

Paste encodeURIComponent('i:0#.f|membership|[email protected]') in any browser's console. It will output something like "i%3A0%23.f%7Cmembership%7Cfirstname.aftername%40domain.se". Finally using following end-point to get user profile properties

/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i%3A0%23.f%7Cmembership%7Cfirstname.aftername%40domain.se'

Update#1

  • It should be console.log(data.d); not console.log(data.d.results);

Try following modified code

$.ajax({
  url: siteUrl+ "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+encodeURIComponent('i:0#.f|membership|[email protected]')+"'",
  type: "GET",
  headers: { "accept": "application/json;odata=verbose" },
  success: function(data, status){
    console.log(data.d);

 },
  error: function(err){
    console.log(err);
  }
});
7
  • It is still empty, i dont recieve anything.
    – Anders
    Dec 8, 2015 at 11:43
  • how did you try? can you update your question? @Jarule Dec 8, 2015 at 11:52
  • I have updated my question now @Atish
    – Anders
    Dec 8, 2015 at 12:00
  • What is the error now? @Jarule Dec 8, 2015 at 12:28
  • Like before, i dont recieve any data
    – Anders
    Dec 8, 2015 at 12:40
0

See example from Microsoft site: /getpropertiesfor(@v)?@v='i%3A0%23.f%7Cmembership%7Cuser%40domain.onmicrosoft.com'"

https://msdn.microsoft.com/en-us/library/office/dn790354.aspx

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.