1

I'm new to using the SP API's and I am having an issue getting the required result using $expand on list lookup columns.

I have 3 lists named ProjectList, SiteList, RegionList with relating lookup's as below.

  • ProjectList with 'Site' lookup
  • SiteList with 'Region' lookup

Project > Site > Region

For example I want to a result which includes RegionTitle, SiteTitle and projectTitle. I'm trying this..

http://<SPSERVER>/<SPSITE>/_api/Web/Lists/GetByTitle('Projects')/items?$select=Title,Site/Title,Site/Region/Title&$expand=Site,Site/Region/

but an getting an error

"The query to field 'Site/Region' is not valid."

However if I try..

http://<SPSERVER>/<SPSITE>/_api/Web/Lists/GetByTitle('Projects')/items?$select=Title,Site/Title&$expand=Site,Site/Region/

this works fine?

Can anyone shed some light on this? can SP only expand to a single lookup level?

Thanks in advance

See this also, a question asking the same thing but was unanswered.. http://stackoverflow.com/questions/19797963/do-sharepoint-2013s-restful-services-support-querying-multi-level-relationship

3

The problem is with the $select query, $select query option is to specify which fields to return for a given list, list item, or other SharePoint object represented by an entity set.

Your ProjectList will not have a field Site/Region/Title, that is the reason your are getting an error The query to field 'Site/Region' is not valid for the first URL.

And as there is no invalid field representaion in the second URL, there is no error.

To retrieve the value of Region field, make another REST call to fetch the data from SiteList with corresponding item ID. In that call use $select query to get the Region lookup.

  • Thanks for that. How do I change the $select to query down to the Region level? is there a setting to specify the depth of the the expand levels or does SP limit this?.. – vikingrs6 Jun 29 '16 at 11:11
  • Updated in my answer – Nagarajan Muthukumar Jun 29 '16 at 11:20

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.