3

I have a list that I am using SharePoint 2013's rest API to grab info from.

I would like to display an image of the user who created the list.

This site shows how to get a user's image url based on their username:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\username'

Using this rest api:

http://siteurl/_api/web/lists/getByTitle('<list_title>')/items

The only information I can find about the user who created the item in the list is the AuthorId

How can you get a user's MySite info based on the AuthorId of a user?

Note:

Microsoft redirects you to the correct user's MySite page if you use this link:

http://siteurl/_layouts/userdisp.aspx?ID=<AuthorId>
4

Using the following call, you can get the Login Name of the user from the AuthorID:

http://siteurl/_api/web/GetUserById(<AuthorID>)/LoginName

And then by using the Login Name, you can get the Picture Url with the following call:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='<LoginName>'&$select=PictureUrl
  • Awesome! One issue: Since we use Claims auth I get this for the login name: i:0#.w|<domain>\<username>. When I remove i:0#.w| and use your second query it works like a charm, otherwise I get an error. Should I just use a string replace to remove that part or is there a better query? – Neil Hoff Jan 25 '14 at 19:24
  • In the first query, you can use the Email property to get only the part you want: http://siteurl/_api/web/GetUserById(<AuthorID>)/Email – Vardhaman Deshpande Jan 26 '14 at 10:24
  • @Vardhaman Deshpande My question is not directly related but somehow relevant. To get the pictureURL, we need to know the MYSITEURL, how do i find out the mysite URl for a user?(other than the constructing the URL from the email which I am aware of) is there an API call which retrieves that info? – Syed Mauze Rehan Jan 4 '16 at 7:46
  • @SyedMauzeRehan you can use the PersonalUrl or UserUrl properties to get the My Site Urls. – Vardhaman Deshpande Jan 4 '16 at 19:43
  • @VardhamanDeshpande Yes indeed, but to get this info i have to know the server URL right? In sharepoint online/office 365 what is that? https://<tenantName>-my.sharepoint.com/_api/sp.userprofiles.peoplemanager/getPropertiesFor('i%3A0%23.f%7Cmembership%7Cadmin%40tenantname.com') is this correct? or do i need to use a different server URL here? – Syed Mauze Rehan Jan 5 '16 at 5:19

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.