0

How do I use rest API to pull data from folders and files? Each set of files are associated to one particular folder. I'm not sure how the are associated and I need to pull certain fields associated to the folder and another set of fields associated to the files.

Is there a way to get the a specific row of items and expand it so the children are available.

The following appear to work, but I do not see the relationship to make one or more calls and associate the folders with the files.


_api/web/lists/getbytitle('production_library')/items?$filter=Business_x0020_Process%20eq%27Communication%20Management%27

_api/web/GetFolderByServerRelativeUrl('production_library/Communication%20Management')

_api/web/GetFolderByServerRelativeUrl('production_library/Communication%20Management')/files

_api/Web/Lists(guid'85d38c8f-9ba0-426e-862e-c0497a1af706')/files('KYiffOP-8Ee2mLxLXncH7uKIVxdXGr9Ftvg6up7WivC7Rc5Eb5v8Rq9Aq-cSEEqN')/Children

0

If your goal is to retrieve a Folder with Files using a single request, then you could utilize the following endpoint:

GET /_api/web/GetFolderByServerRelativeUrl('<folder url>')?$expand=Files

Example

Assume a Documents library that contains Guides folder, then the following example demonstrates how to retrieve a Folder with Files:

function getFolderWithFiles(webUrl,folderUrl) 
{
    var endpointUrl = webUrl + "/_api/web/GetFolderByServerRelativeUrl('" + folderUrl + "')?$expand=Files";
    return $.getJSON(endpointUrl);
}

var webUrl = _spPageContextInfo.webAbsoluteUrl;
getFolderWithFiles(webUrl,'Documents/Guides').done(function(folder){
    console.log(folder.Name); //print folder name
    for(var i = 0;i < folder.Files.length;i++) {
        console.log(folder.Files[i].Name); //print file name
    }

});

References

Files and folders REST API reference

  • For some reason a particular field or property was not showing up. You suggesting allowed me to pull that field with an addition. Now Task_x0020_Description is available at the file level. _api/web/GetFolderByServerRelativeUrl('production_library/Communication%20Management')?$expand=Files/listitemallfields – Bitspider Feb 1 '15 at 22:56

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.