0

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.

  • try this once appUrl/_api/Sp.AppContextSite(@target)/Web/…' – TARUN May 25 '17 at 9:59
  • @TARUN it didn't worked. Getting same error. – Piyush May 25 '17 at 11:08
  • ?$expand=Author&$select=Author/Id,Author/Title – Marco May 25 '17 at 14:00
  • @Marco I have used both, $expand=Author as well as $expand=Author/ID None of them worked. Getting the same error! – Piyush May 25 '17 at 15:03
  • if you make the call with no parameters, just items did it show the author column? – Marco May 25 '17 at 15:06
0

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.

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.