5

I have a SharePoint(Online) list which has around 50 columns. Out of which 6 are lookup columns. I am trying to write a REST query to get all the columns including the expansion($expand) of lookup columns. Specifying all the columns in '$select' will make the REST query URL to exceed the limit allowed by IE. But to expand the lookup columns I need to specify them in the '$select'.

?$select=col1,col2,col3/Title,col4/Title.....,col54&$expand=col3,col4

Is there a way to access all columns from the lists without making multiple request to the server?

Jijo Joy
  • 53
  • 1
  • 1
  • 5
  • Take a look at the [SP PnP JS](https://github.com/SharePoint/PnP-JS-Core/wiki/Basic--Operations?#user-content-odata-operators) framework. It simplifies the process of using ajax requests to fetch list data and it also supports `expand`. Just add the [pnp.min.js](https://github.com/SharePoint/PnP-JS-Core/blob/master/dist/pnp.min.js) file to your solution and then access the 'pnp' object with `$pnp` – Jackson Mar 13 '17 at 21:57

1 Answers1

9

you can try using * for all the columns.

In below example, * has been used to get all the columns. Country and State are lookup columns so they have been used along with * as they are part of $expand.

https://site/_api/lists/getbytitle('TestLookup')/items?$select=*,Country/Title,State/Title&$expand=Country/Id,State/Id
Anit
  • 174
  • 5
  • "Like a hot knife through butter" - it worked with ease. I was under the impression that * and column names cannot be used together in $select clause. Thank you @Anit-K – Jijo Joy Mar 14 '17 at 17:02
  • weird.. does not work for me in my SharePoint Online tenant. $select=* just does nothing... – Denis Molodtsov Mar 26 '17 at 00:52
  • This will return all the columns from the list, but only "Title" from the lookup lists. Is there any way to get all the columns of the current list and the list that is linked to ( by the use of a lookup column) ? thanks. – Alberto S. Aug 07 '17 at 15:53
  • Denis: You cannot just do *, that is by default, the API will return all columns if you do not use a select query parameter. It must be used WITH what you are trying to access (see example above specifically accessing properties on Country and State) and it is for this use case only. – kittycatbytes Jun 15 '18 at 14:45