Question

I have a list in SharePoint 2013 Online. This list has a column that is a PersonOrGroup type. I'm using REST APIs to retrieve the items of this list, and I want to retrieve all the data for the PersonOrGroup column. I just learned how to expand the PersonOrGroup data to return its fields. How do I find out all the available fields in the PersonOrGroup type? Any links to documentation would be great.

REST call:
<base url>/_api/web/lists/my_list/items?$select=my_col/Name&$expand=my_col

I know a 'Name' field exists, because it is returning the name of the person/group. But I don't know what other fields I can retrieve. Looking at the PersonOrGroup settings through Internet Explorer, I see the following fields in the "Show field" dropdown:

  • Title
  • First name
  • Last name
  • Organization
  • List item
  • List item
  • ID
  • Name (with presence)
  • etc.

I imagine these correspond to the fields of the PersonOrGroup type, but how do I reference them in the REST API call? For example, how do I know what to pass in for the 'First name' field? It could be many things like "first_name", "first-name", "firstname", "first%20name", etc.

Was it helpful?

Solution

Here is a technique that will work for any lookup type because it goes to the lookup list for the field you're interested in:

You can make a REST request to the /fields endpoint on your list to retrieve some more information about the fields that exist within the list.

For your case, you're interested in fields of the person or group type so you could do something like this (assuming you're in a browser window on your SP site using JavaScript with a reference to jQuery -- but you can satisfy these criterea artificially to check the results yourself if in a different environment):

$.getJSON("/_api/web/lists/getByTitle('yourList')/fields?$filter=TypeDisplayName eq 'Person or Group'")
    .then(function(data) { console.log(data) })
    .fail(function(jqXHR) { console.log(jqXHR.responseText) })

I'm using the browser dev tool consoles so I can see the response objects.

Now inside the data returned from this will have an array containing all of the fields that are of the Person or Group type.

You can use this information to go back to the lists where they lookup data from by finding the LookupList property for that field. Then finally you can go get a request for some items in that list to see the available property names:

$.getJSON("/scratch/_api/web/lists('{guidYouLookedUpFromYourField}')/items")
    .then(function(data) { console.log(data) })
    .fail(function(jqXHR) { console.log(jqXHR.responseText) })

Here are the fields available in my SiteUserInfoList which applies directly to your question:

{
  "odata.type": "SP.Data.UserInfoItem",
  "odata.id": "b09721bb-1505-4f93-ad24-e718fce66c31",
  "odata.etag": "\"1\"",
  "odata.editLink": "Web/SiteUserInfoList/Items(14)",
  "FileSystemObjectType": 0,
  "Id": 14,
  "ContentTypeId": "0x010A0076E50CD586E0514794008EF63DFE0307",
  "Title": "Test User",
  "Name": "i:0#.f|membership|testuser@someone.onmicrosoft.com",
  "EMail": null,
  "MobilePhone": null,
  "Notes": null,
  "SipAddress": null,
  "IsSiteAdmin": false,
  "Deleted": false,
  "UserInfoHidden": false,
  "Picture": null,
  "Department": null,
  "JobTitle": null,
  "FirstName": null,
  "LastName": null,
  "WorkPhone": null,
  "UserName": null,
  "WebSite": null,
  "SPSResponsibility": null,
  "Office": null,
  "SPSPictureTimestamp": null,
  "SPSPicturePlaceholderState": null,
  "SPSPictureExchangeSyncState": null,
  "ID": 14,
  "Modified": "2014-12-09T14:36:37Z",
  "Created": "2014-12-09T14:36:37Z",
  "AuthorId": 9,
  "EditorId": 9,
  "OData__UIVersionString": "1.0",
  "Attachments": false,
  "GUID": "b344f215-0dbe-4732-b5d1-4c29c3b444ab"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top