1

/_api/web/lists/getbytitle('List')/items?$select=Id,AttachmentFiles&$expand=AttachmentFiles

The above REST endpoint works in SharePoint online and we are able to fetch attachments but the same endpoint doesn't work for SharePoint 2013 on-premise enterprise version.

I get the following error.

Bad request

I get details when I drop $select and use just expand as follows:

/_api/Web/Lists/getByTitle('List')/items?$expand=AttachmentFiles

But if I use this I cannot expand extended lookup fields in the same list as the fields are required to be added to $select

What could be the reason? Is there anything that I can do where I get both attachments and extended lookup using same query.

  • Could you provide more information about how it's not working? Is the page throwing an error, returning no data, or a 404? – Aron Foster Apr 9 '15 at 15:48
  • I get a Bad request error in on-prem but the same query works fine in online.Does the same work at your on-prem? – Harshini Hegde Apr 9 '15 at 15:53
  • Please update your question with that data. Also include what version of SharePoint you're using. That'll help get you a good answer. – Aron Foster Apr 9 '15 at 15:57
  • I have edited my post – Harshini Hegde Apr 9 '15 at 16:03
  • 2
    I'm not 100% sure, but I think the reason it doesn't work on on-premise is because it shouldn't work. 365 is much more forgiving about OData, like you don't need odata=verbose;, probably because of early access and compatibility with already built stuff. The thing is that OData doesn't let you do wildcard select on expanded properties, and for this to work you need that. This is two levels of arrays, think about it as selecting all lists, then all items for all lists, and then selecting properties in the items - not straight forward. As you probably know, if you drop the $select it works – eirikb Apr 9 '15 at 19:11
0

Just tested your REST call in my SharePoint 2013 Enterprise environment and it works correctly.

Make sure your list has attachments turned on. List Settings>Advanced Settings> Attachments. Set to Enabled.

Make user the Title in the url correctly matches a list in your on-prem site.

  • 1
    Attachements is enabled and the Url is also correct.Like eirikb said I get attachmentFiles values when i drop $select and use just expand as follows:/_api/Web/Lists/getByTitle('List')/items?$expand=AttachmentFiles .But if I use this I cannot expand extended lookup fields as the fields are required to be added to $select – Harshini Hegde Apr 10 '15 at 6:26
0

REST API calls for dealing with attachments is not consistent between SharePoint 2013 / On Premises and SharePoint Online.

SharePoint Online Including AttachmentFiles in the $select and $expand collections is enough. The Attachment field is automatically returned in the results set.

SharePoint 2013 / On Premises You must include both AttachmentFiles, Attachments in the $select statement. The $expand collections must still contain AttachmentFiles. This method is recommended if you'd like your REST call to run in both versions of SharePoint.

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.