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.