7

I have a list which has a "People and Group" column. when I query the rows using REST, I get user Ids listed in this column.

I found this article which will help me in converting each id to a title

http://www.codeproject.com/Articles/692289/How-to-Get-Login-Name-and-Display-Name-using-Sha

But I am wondering if there is a way in which I can get the user title by a single REST call (rather than first get the ID and then making another call to convert the ID into the user display name and the login name)

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

2 Answers2

18

Using $expand OData operator you can specify that the request returns projected fields from other lists and the values of lookups.

The following REST endpoint:

/_api/web/lists/getbytitle('Pages')/items(1)?$select=Author/Name,Author/Title&$expand=Author/Id

returns Title and Name for Author column in Pages list

{
    "d": {
        "__metadata": {
            "id": "63b9e943-6398-4b6d-acc9-fc4f554f78df",
            "uri": "https://contoso.sharepoint.com/_api/Web/Lists(guid'be43ccf2-5ca7-4957-bf81-7cdc86744d9b')/Items(1)",
            "etag": "\"6\"",
            "type": "SP.Data.PagesItem"
        },
        "Author": {
            "__metadata": {
                "id": "8e4ad44e-f6f0-4dcc-92c6-78dc3d2c68af",
                "type": "SP.Data.UserInfoItem"
            },
            "Name": "i:0#.f|membership|username@contoso.onmicrosoft.com",
            "Title": "John Doe"
        }
    }
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • 1
    Is it possible to modify this API call to get any user's profile data? I need a generic way to get user data by the display name. These users would be part of the "Everyone" group listed under Site Vistiors. – julian soro May 14 '14 at 22:15
  • 1
    No you can only get the user information that is on the site users list, which is not that much more than a name and email. – sjkp Jul 01 '14 at 15:20
  • 2
    Thanks for the answer! It works for all the lookup fields on my table. What about for those fields with multiple users (Type="UserMulti")? How can I get the name of all users? – Richard H Oct 01 '14 at 20:11
  • does the profile picture be part of the metadata retrieved with this expand query ? I don't see any microsoft documentation on the fields which belongs to the SP.Data.UserInfoItem object. – Alex Jun 08 '15 at 09:10
  • Getting user information is pretty easy: http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html – sandrooco Nov 17 '15 at 10:28
1

You can use the below rest query to get the modified by user's title: /_api/web/lists/getbytitle('Pages')/items(1)?$select=Editor/Name,Editor/Title&$expand=Editor/Id