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.





1 Answer 1


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


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;
    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



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
    Commented Feb 1, 2015 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.