0

I allowed the creation of folders in the list, and the content type "DinamicoFolder" is of type folder. enter image description here

I have multiple folders inside the folder "Contas à Ordem" enter image description here

URL: https://test.sharepoint.com/sites/dinamico/Negocio/OfertaParticulares/_api/web/lists('94e42b17-3fa0-4057-84e2-1fde65ea735c')/items

How can I get the first folder? and the folders inside?

0

While what Rob is suggesting will certainly work, you can also just get to the folders directly. Initially, make a query for the root folder of the library you are working with:

https://server/sites/your/site/_api/web/lists('your-guid')/rootfolder

or

https://server/sites/your/site/_api/web/lists/getbytitle('library name')/rootfolder

In the result of that query, you will see it has a property

d.Folders.__deferred.uri

That URI is an absolute URL, so use that as your next query to get the subfolders of the root folder. This will return your "Contas a Ordem" folder, as well as the default "Forms" folder. But if you look at the properties on your "Contas a Ordem" folder, you will see that it also has a Folders.__deferred.uri property that you can use in your next query to get the subfolders of "Contas a Ordem".

And once you get those, you will see that they each also have a Folders.__deferred.uri property that you can use to get their subfolders, and so on and so on.

Incidentally, you will also see that all the folder objects returned also have a Files.__deferred.uri property that will give you a URI to get the files inside that folder.

0

I cover this and more in SharePoint REST API and Lists with Folders

Requesting the Items collection for the list will bring back all items and folders regardless of what folder they are in. You can use the FileSystemObjectType or ContentType property to determine if the item is or is not a folder. In the example below I'm using the FileSystemObjectType.

function getItemsOrFolders(fileSystemObjectType) {
    var appUrl = GetUrlKeyValue("SPAppWebUrl");
    var hostUrl = GetUrlKeyValue("SPHostUrl");

    var message = jQuery("#message");
    message.text("Working on it...");

    var url = appUrl + "/_api/SP.AppContextSite(@target)" +
        "/Web/Lists/getByTitle('FolderTest')/Items?$select=*,FileDirRef&" +
        "@target='" + hostUrl + "'";

    var call = jQuery.ajax({
        url: url,
        type: "GET",
        dataType: "json",
        headers: {
            Accept: "application/json;odata=verbose"
        }
    });
    call.done(function (data, textStatus, jqXHR) {
        var fileOrFolderText = "files";
        if (fileSystemObjectType == SP.FileSystemObjectType.folder) {
            fileOrFolderText = "folders";
        }
        message.text("All " + fileOrFolderText + ":");
        message.append("<br/>");
        jQuery.each(data.d.results, function (index, item) {
            if (item["FileSystemObjectType"] == fileSystemObjectType) {
                message.append(String.format(
                    "Title: {0};  Number: {1};  Id: {2}; Path: {3}",
                    item["Title"], item["Number"], item["Id"], item["FileDirRef"]));
                message.append("<br/>");
            }
        });
    });
    call.fail(failHandler);
}

enter image description here

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.