Question

I am trying to use the OData $expand query option to fetch the Title of a SharePoint User Field. The field name is, Author (Created By). However, on using the $expand option, I am getting the following error,

The $expand query is not valid for field 'Author'.

Following is the URL that I am using to fetch the data.

https://appUrl/_api/Sp.AppContextSite(@target)/Web/Lists(guid'guid')/items?$select=Number1,Author/Title&$expand=Author/ID&@target='targetSiteUrl'

Interestingly, if I use the following URL from a SharePoint Content Editor Web Part then everything is working fine!

http://targetSiteUrl/_api/Web/Lists(guid'guid')/items?$select=Number1,Author/Title&$expand=Author/ID

So, my question is, am I doing something wrong or we cannot use $expand from within the scope of a SharePoint App? As of now, it works fine directly from the site but not from the add-in.

Was it helpful?

Solution

The issue was that for the method items, used in the given URL, I was sending the type as POST instead of GET in my app!

However, from the Content Editor Web Part, I am not setting this value so by default GET is correctly getting passed.

You can also check the detailed answer here.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top