Search All Folders

Searches all folders that match the user-provided criteria.

Note: For more information about this command, including descriptions of any path and request parameters, request body schema, response codes and schemas, and payload examples, refer to the online API reference for this command at the following web page:

Search all folders

URI

https://bartendercloud.com/api/librarian/spaces/{spaceId}/folders/search

Note: The bartendercloud.com domain that is referenced in the URI and in the code example that follows must be replaced with the contents of the DataCenterURI claim that is extracted from your access token. For more information, refer to Extracting the DataCenterURI Claim.

Path Parameters

spaceId

Type: Integer <int32>

Specifies the ID of the requested space. Use the number 1 to target the Main space or the number 2 to target the $temp space. Required.

Query Parameters

None.

Example

Request body: See SearchFoldersRequest.

Response: See SearchFoldersResult.

Copy
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");

var searchRequest = new SearchFoldersRequest() {
    FolderNameContainsQuery = "labels",    // Search for folder names that contain the substring "label".
    Limit = 100,                           // Limit each query to 100 responses.
    Skip = 0                               // Start the search at the beginning.
};

int spaceId = 1; // Search the Main space.
List<SearchFolderResult> folderResults = new List<SearchFolderResult>();

// The search API returns paged responses. In this sample query, all pages 
// return the complete set of folders that match the search criteria.
do
{
    HttpRequestMessage request = new HttpRequestMessage
    {
       RequestUri = new Uri($"https://bartendercloud.com/api/librarian/spaces/{spaceId}/folders/search"),
       Content = new StringContent(JsonConvert.SerializeObject(copyRequest), Encoding.UTF8, "application/json"),
       Method = HttpMethod.Post
    };

    HttpResponseMessage msg = await client.SendAsync(request);

    if (msg.IsSuccessStatusCode)
    {
        var result = JsonConvert.DeserializeObject<SearchFoldersResult>(await msg.Content.ReadAsStringAsync());
        folderResults.AddRange(result.SearchResultFolderMatches);

        // Stop the search if the full set of folders has been processed.
        if (SearchCompleted)
            break;

        // An additional query might return more records.
        searchRequest = result.NextSearchFoldersRequest;
    }
    else
    {
        throw new Exception("Query failed");
    }
} while (true);