# Folder recursive search

## Overview

This endpoint is one of Sitefinity’s OData web services custom methods. Custom methods are denoted by the `Default.{MethodName}` convention.

Custom methods are one of the following:

* Bound\
  Bound methods require an entity to execute.\
  In this case, `FoldersRecursiveSearch` is a bound method.
* Unbound\
  Unbound methods do not require an entity to execute.

The `FoldersRecursiveSearch` method can be executed for the following entity sets:

* `albums`
* `videolibraries`
* `documentlibraries`

To run a recursive folder search, execute a `GET` request to the following endpoint:

`{baseUrl}/api/default/{entity}/Default.FoldersRecursiveSearch(parentId={itemId}`

Where:

* `{entity}` is the entity of the module that you are working with. It is one of `albums`, `videolibraries`, or `documentlibraries`.
* `{itemId}` is the ID of the library where you want to execute the method. It can be `null`.

The method has an optional query string parameter `?recursive=true`. If you omit it, it defaults to `false`.

* If you use the method with `?recursive=true`, it will return all levels of folders of the targeted library.
* If you use the method with `recursive=false`, the endpoint will return only the first level.

This method returns a DTO with the following properties:

* `Breadcrumb: Array`
* `ChildrenCount: Number`
* `Description: String`
* `FoldersCount: Number`
* `Id: GUID`
* `LastUploaded: Date`
* `LastUploadedBy: Sting`
* `MaxLibrarySizeInKb: Number`
* `ParentId: GUID?`
* `PreviewItems: Array`
* `RootId: GUID?`
* `RunningTask: GUID?`
* `Storage: String`
* `Title: String`
* `TotalLibrarySizeInKb: Number`

> success **EXAMPLE**: The following examples use the structure of Sitefinity CMS *Document* libray. There are two root libraries – *Presentations* and *Samples*. The *Samples* library has one child folder – *Large documents*. If the `FoldersRecursiveSearch` method is called recursively, without specifying a parent, it will return all of these items.

## Execute recursive search

**Sample request**

> success  **GET** `http://mysite.com/api/default/documentlibraries/Default.FoldersRecursiveSearch(parentId=null)?recursive=true`

**Sample response**

<SfDetails summary="Status code: 200 OK">

```JSON
{
    "@odata.context": "http://mysite.com/api/default/$metadata#Collection(Telerik.Sitefinity.Modules.Libraries.Web.Services.OperationProvider.ExtendedFolder)",
    "value": [
        {
            "MaxLibrarySizeInKb": 0,
            "TotalLibrarySizeInKb": 9,
            "LastUploadedBy": null,
            "LastUploaded": null,
            "Storage": "Database",
            "FoldersCount": 0,
            "ChildrenCount": 0,
            "Id": "896a1e5a-44c1-44e8-89d0-23567dd16907",
            "Title": "Presentations",
            "Description": "",
            "ParentId": "00000000-0000-0000-0000-000000000000",
            "RootId": null,
            "RunningTask": "00000000-0000-0000-0000-000000000000",
            "PreviewItems": [],
            "Breadcrumb": []
        },
        {
            "MaxLibrarySizeInKb": 0,
            "TotalLibrarySizeInKb": 17697,
            "LastUploadedBy": null,
            "LastUploaded": null,
            "Storage": "FileSystem",
            "FoldersCount": 1,
            "ChildrenCount": 0,
            "Id": "13f352fe-5bcc-4374-a234-0376f68bebc0",
            "Title": "Samples",
            "Description": "",
            "ParentId": "00000000-0000-0000-0000-000000000000",
            "RootId": null,
            "RunningTask": "00000000-0000-0000-0000-000000000000",
            "PreviewItems": [],
            "Breadcrumb": []
        },
        {
            "MaxLibrarySizeInKb": 0,
            "TotalLibrarySizeInKb": 17697,
            "LastUploadedBy": null,
            "LastUploaded": null,
            "Storage": null,
            "FoldersCount": 0,
            "ChildrenCount": 0,
            "Id": "7dff9bd1-518a-42eb-a985-7d1954f47804",
            "Title": "Large documents",
            "Description": "",
            "ParentId": "13f352fe-5bcc-4374-a234-0376f68bebc0",
            "RootId": "13f352fe-5bcc-4374-a234-0376f68bebc0",
            "RunningTask": null,
            "PreviewItems": [],
            "Breadcrumb": [
                {
                    "Title": "Samples",
                    "FolderId": "13f352fe-5bcc-4374-a234-0376f68bebc0"
                }
            ]
        }
    ]
}
```

</SfDetails>

## Execute non-recursive search

Alternatively, if the method is called without the `?recursive` query parameter, it defaults to `?recursive=false`. The result will not include the child folder *Large documents*.

**Sample request**

> success  **GET** `http://mysite.com/api/default/documentlibraries/Default.FoldersRecursiveSearch(parentId=null)`

**Sample response**

<SfDetails summary="Status code: 200 OK">

```JSON
{
    "@odata.context": "http://mysite.com/api/default/$metadata#Collection(Telerik.Sitefinity.Modules.Libraries.Web.Services.OperationProvider.ExtendedFolder)",
    "value": [
        {
            "MaxLibrarySizeInKb": 0,
            "TotalLibrarySizeInKb": 9,
            "LastUploadedBy": null,
            "LastUploaded": null,
            "Storage": "Database",
            "FoldersCount": 0,
            "ChildrenCount": 0,
            "Id": "896a1e5a-44c1-44e8-89d0-23567dd16907",
            "Title": "Presentations",
            "Description": "",
            "ParentId": "00000000-0000-0000-0000-000000000000",
            "RootId": null,
            "RunningTask": "00000000-0000-0000-0000-000000000000",
            "PreviewItems": [],
            "Breadcrumb": []
        },
        {
            "MaxLibrarySizeInKb": 0,
            "TotalLibrarySizeInKb": 17697,
            "LastUploadedBy": null,
            "LastUploaded": null,
            "Storage": "FileSystem",
            "FoldersCount": 1,
            "ChildrenCount": 0,
            "Id": "13f352fe-5bcc-4374-a234-0376f68bebc0",
            "Title": "Samples",
            "Description": "",
            "ParentId": "00000000-0000-0000-0000-000000000000",
            "RootId": null,
            "RunningTask": "00000000-0000-0000-0000-000000000000",
            "PreviewItems": [],
            "Breadcrumb": []
        }
    ]
}
```

</SfDetails>

## Execute a search with partentID

When you call the `FoldersRecursiveSearch` method with a populated `parentId` parameter, the method returns the folders only of the targeted library. This example uses the ID of the *Samples* library from the previous example – `13f352fe-5bcc-4374-a234-0376f68bebc0`.

**Sample request**

> success  **GET** `http://mysite.com/api/default/documentlibraries/Default.FoldersRecursiveSearch(parentId=13f352fe-5bcc-4374-a234-0376f68bebc0)`

**Sample response**

<SfDetails summary="Status code: 200 OK">

```JSON
{
    "@odata.context": "http://mysite.com/api/default/$metadata#Collection(Telerik.Sitefinity.Modules.Libraries.Web.Services.OperationProvider.ExtendedFolder)",
    "value": [
        {
            "MaxLibrarySizeInKb": 0,
            "TotalLibrarySizeInKb": 17697,
            "LastUploadedBy": null,
            "LastUploaded": null,
            "Storage": null,
            "FoldersCount": 0,
            "ChildrenCount": 0,
            "Id": "7dff9bd1-518a-42eb-a985-7d1954f47804",
            "Title": "Large documents",
            "Description": "",
            "ParentId": "13f352fe-5bcc-4374-a234-0376f68bebc0",
            "RootId": "13f352fe-5bcc-4374-a234-0376f68bebc0",
            "RunningTask": null,
            "PreviewItems": [],
            "Breadcrumb": [
                {
                    "Title": "Samples",
                    "FolderId": "13f352fe-5bcc-4374-a234-0376f68bebc0"
                }
            ]
        }
    ]
}
```

</SfDetails>
