2

Why doesn't the following string returns data from within a folder in the same asset library:

Asset Library Name is Production_Library

Folder Name is at the top level of the asset library and is named Communication Management

The filter works nicely here at the /items level filtering against the Business Process field.


https://gumdrops.sharepoint.com/sites/Training/_api/web/lists/getbytitle('production_library')/items?$filter=Business_x0020_Process eq 'Communication Management'

However, the filter doesn't work at all here within the folders against the Name Field.


https://gumdrops.sharepoint.com/sites/Training/_api/web/lists/getbytitle('production_library')/files?$filter=Name eq 'Communication Management'
2

Selecting items in folders with the REST API is a bit different than selecting items in the library itself... (like in your first example)

The way that I get the items in a specific folder is with the /_api/web/GetFolderByServerRelativeUrl("<serverRelativeFolderUrl>")/files endpoint...

So in your example, you want everything in Production_Library/Communication Management (notice that you don't have to url encode the space)

I'm assuming that Production_Library sits at the root of your site, so your path may be slightly different, but to get all of the items in the Communication Management folder you would use a request to:

/_api/web/GetFolderByServerRelativeUrl('/Production_Library/Communication Management')/files

Your second request in the question would actually go to the /files endpoint against the Production_Library document library and look for a file that has a Name of Communication Management -- which you've noticed doesn't work... A request like that returns a 400 error for me in SharePoint online when I try to filter the /files endpoint by Name -- but even if it did work you wouldn't be getting the items inside of the folder like you're looking for.

  • good comment, but doesn't help the cause. – Bitspider Feb 1 '15 at 5:40
  • 1
    I think you'll find the endpoint I suggested "returns data from within a folder in the same asset library" as your question asks -- otherwise you may need to clarify what you are looking for. – John-M Feb 1 '15 at 19:00
  • 1
    John, sorry about that and Big Thanks. I took another look at it. GetFolderByServerRelativeUrl works perfectly. Now, I need to figure out how to filter for files ending with .docx & .pdf . – Bitspider Feb 1 '15 at 20:00
3

Your second query just returns files filtered by File.Name and nothing more.

The following examples demonstrates how to retrieve files from a specific folder.

How to retrieve Files from a specific Folder using SharePoint REST

Assume a Documents library contains Guides folder.

Option 1

Using SP.Web.getFolderByServerRelativeUrl Method

Endpoint Uri: GET /_api/web/GetFolderByServerRelativeUrl('documents/guides')/files

Option 2

Using CAML query

Endpoint Uri: POST /_api/web/lists/getbytitle('Documents')/getitems

Body:

{  
      'query' : {
                 '__metadata': { 'type': 'SP.CamlQuery' }, 
                 'ViewXml' : '<View><Query/></View>',
                 'FolderServerRelativeUrl': '/Documents/Guides'  
       }
}

Headers:

  • X-RequestDigest: value
  • Accept: application/json; odata=verbose
  • Content-Type: application/json; odata=verbose
  • Vadim, thanks. I'm not sure how to implement the caml querries, so I'll try to see if I can get this to work. It appears to be a bit more effective. – Bitspider Feb 1 '15 at 20:03
  • 1
    This is a nice technique for combining a CAML query with the REST API that I hadn't seen before -- thanks Vadim! – John-M Feb 3 '15 at 16:41
  • how to get the folders from asset library – Shreyas Sep 10 '15 at 11:18
  • Is there any way to mention the FolderServerRelativeUrl inside the viewXml? Like the Queryoptions node has a folder node. Does that work with SharePoint 2013? – Unnie Jan 22 at 15:44

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.