2

I would like to drill into the library and then into a specified folder, but I am having problems getting 'getFolderByServerRelativeUrl' to grab anything for me.

This http://_base/_api/web/getFolderByServerRelativeUrl('LibName')/files returns zero results. But if I use http://_base/_api/web/lists/getbytitle('LibName')/items it returns multiple items.

Chetdu
  • 136
  • 1
  • 2
  • 12
  • Not sure if it matters, but have you tried using a `/` before the library name when trying to access by server**relative**url? – Daniel B Jul 28 '15 at 06:52
  • I have but that doesn't get anything either. Thanks for the comment. – Chetdu Jul 28 '15 at 18:35

2 Answers2

6

/_api/web/lists/getbytitle('<list title>')/items endpoint returns all list items within a library, /_api/web/getFolderByServerRelativeUrl('<url>')/files returns only files located under (one level beneath only) the specified folder.

Example

Assume the following Documents library structure:

Documents (library)
   |
   Guides (folder)
     |
     SharePoint User Guide.docx (file)

Then, the following request:

/_api/web/lists/getbytitle('Documents')/items will return 2 items:

  • list item associated with Guides folder
  • list item associated with file

At the same time, the request: /_api/web/getFolderByServerRelativeUrl('Documents')/files

will returns 0 files since there are no files contained in the root folder

but the request with provided folder url: /_api/web/getFolderByServerRelativeUrl('Documents/Guides')/files

will return SharePoint User Guide.docx file.

Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
-1

You're using the wrong URL. Try appending it to the other URL.

Joshua Smith
  • 134
  • 10