4

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|firstname.aftername@sitename.sharepoint.com')+"'";


 $.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?

3

May be you are missing encodeURIComponent()

URL should look like

/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+encodeURIComponent('i:0#.f|membership|firstname.aftername@domain.se')+"'

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

If you are using any REST client, then convert i:0#.f|membership|firstname.aftername@domain.se into encodeURIComponent at first.

Paste encodeURIComponent('i:0#.f|membership|firstname.aftername@domain.se') 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|firstname.aftername@sitename.sharepoint.com')+"'",
  type: "GET",
  headers: { "accept": "application/json;odata=verbose" },
  success: function(data, status){
    console.log(data.d);

 },
  error: function(err){
    console.log(err);
  }
});
  • It is still empty, i dont recieve anything. – Anders Dec 8 '15 at 11:43
  • how did you try? can you update your question? @Jarule – Atish Dipongkor - MVP Dec 8 '15 at 11:52
  • I have updated my question now @Atish – Anders Dec 8 '15 at 12:00
  • What is the error now? @Jarule – Atish Dipongkor - MVP Dec 8 '15 at 12:28
  • Like before, i dont recieve any data – Anders Dec 8 '15 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, privacy policy and cookie policy

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