How to get the REST API to load only the library folders without the elements and documents in them?

2 Answers 2


Full correct answer:

var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Document')/items?$select=FSObjType,BaseName";
var requestHeaders = {
    "accept": "application/json;odata=verbose"
    url: requestUri,
    type: 'GET',
    dataType: 'json',
    headers: requestHeaders,
    success: function (data) 
       $.each(data.d.results, function(i,result) {
        var name = result.FSObjType;
        if(name == 1) {
            var namefolder = [];
    error: function ajaxError(response) {
        alert(response.status + ' ' + response.statusText);

if you need only folder name, use FSObjectType integer = 1 (folder), then BaseName (folder name) or FileRef (but this full name documents\ "Document\folder name")...))


The following call returns items with a file type of Folder:

/_api/web/Lists/GetByTitle('Name of the Library')/Items?$expand=Folder&$select=Title,Folder/ServerRelativeUrl

SP2010 approach would be the following:

/_vti_bin/listdata.svc/DocLib?$filter=ContentType eq 'Folder'
  • What element to take into value (result)?
    – user37251
    Jun 26, 2017 at 9:39
  • 1
    It's up to you what you wish to include. The available properties of a Folder can be found here: msdn.microsoft.com/en-us/library/office/dn450841.aspx#bk_Folder. We can see that available properties are e.g. ItemCount, Name, ParentFolder and WelcomePage.
    – moe
    Jun 26, 2017 at 9:45

Your Answer

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