3

I am trying to retrieve all field values of a specific list item via the REST-API of SharePoint 2013. The values will be used for further processing. The goal is to retrieve all field values dynamically, so manually specifying the required fields is out of the question. The requests are done from a Java-Applikation, so I am building the HTTP-Requests myself and not with CSOM or JSOM.

I tried the following ideas, but without satisfying results:

Simple request to /_api/web/lists(guid)/items(id)/FieldValuesAsText. The problem with this approach is, that all values are returned as Strings, so I don't get typed values from the JSON parser. Also some values like dates are formatted, e.g. "8/8/2014 3:31 PM", which is not usable, as I need dates in ISO-8601 format.

My second approach was to first do a select to retrieve all available fields with /_api/web/lists(guid)/items(id)/ParentList/Fields and then build a select on the list item, based on the EntityPropertyName of each field. This would result in something like /_api/web/lists(guid)/items(id)?$select=Id,Created,Author,.... Problem is, that for example a query with $select=Author does not work, as Author needs to be specified in the $expand-Parameter.

Error:

The query to field 'Author' is not valid. The $select query string must specify the target fields and the $expand query string must contains Author.

And I could not find a way to determine which fields have to be expanded and which not.

My third approach was similar to number two, but retrieve each field from the list item with a separate request: /_api/web/lists(guid)/items(id)/Author. With this I can also retrieve expanded field values as objects and don't have to deal with an $expand-Parameter in the select. The Problem with this method is that it is very slow as there are approximately 60 requests executed for just a single list item.

Does anyone know another method the retrieve all field values of a list item?

  • Object.keys() will get you all the keys in the JSON object, but will include stuff like __metadata, and other fields you may not be interested in. But you can use that to loop through them all. – wjervis Aug 11 '14 at 13:22
12

How about a simple query:

 /_api/web/lists/getbytitle('<list title>')/items(<item id>)

which will return all the field values for a list item with some limitation for User/Lookup fields:

  • only lookup id values will be retrieved.

In order to request all the field values including User/Lookup field values, you could specify * to select all the fields plus to specify projected fields explicitly:

/_api/web/lists/getbytitle('<list title>')/items(<item id>)?$select=<projected field>/Id,<projected field>/Title,*&$expand=<projected field>

For exampe; in order to request all the field values including projected fields (like Author and Editor user fields) the following query could be used:

/_api/web/lists/getbytitle('<list title>')/items(<item id>)?$select=Author/Id,Author/Title,Editor/Id,Editor/Title,*&$expand=Author,Editor
  • 1
    Ok, I did try the select with a star ($select=*), but it doesn't do anything for me, I get the exact same fields as when I don't specify a $select. I could actually live with specifying every field in the $select (my second approach). But as I have to support (theoretically) every possible configuration, how can I determine the fields to expand? Are only User-Fields expandable? – Dave Aug 12 '14 at 17:38
  • User and lookup field values are expandable at least. Regarding $select=*, it indeed returns all the field values but it could be useful when you construct the query to return all the field values plus projected field values – Vadim Gremyachev Aug 12 '14 at 18:14

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.