List Items by Folder ID

Lists the files and subfolders that are contained in the target folder by using the folder ID.

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:

List items by folder ID

URI

https://bartendercloud.com/api/librarian/items/{folderId}

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

folderId

Type: String

Specifies the ID of the requested folder. Required.

Query Parameters

None.

Example

Request body: See ItemsRequest.

Response: See Items.

Copy
// Assume that folderId contains the ID of the target folder.
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");

var itemsRequest = new ItemsRequest() {
    FoldersLimit = 100,        // Read folders in batches of 100.
    FilesLimit = 100,        // Read files in batches of 100.
    FoldersSkip = 0,        // The first read of the folder starts at the beginning.
    FilesSkip = 0,            // The first read of the files starts at the beginning.
    IncludeHidden = false,    // Do not include hidden folders or files.
    IncludeDeleted = false    // Do not include deleted folders or files.
};

FolderNoChildren targetFolder = null;
var files = new List<File>();
var subfolders = new List<FolderNoChildren>();
do
{
    HttpRequestMessage request = new HttpRequestMessage
    {
        RequestUri = new Uri($"https://bartendercloud.com/api/librarian/items/{folderId}"),
        Content = new StringContent(JsonConvert.SerializeObject(itemsRequest), Encoding.UTF8, "application/json"),
        Method = HttpMethod.Post
    };

    HttpResponseMessage msg = await client.SendAsync(request);

    if (msg.IsSuccessStatusCode)
    {
        var items = JsonConvert.DeserializeObject<Items>(await msg.Content.ReadAsStringAsync());

        targetFolder = items.Folder;
        files.AddRange(items.Files);
        subfolders.AddRange(items.Subfolders);

        if (items.MoreItemsToGet)
            itemsRequest = items.NextItemsRequest;
        else
            break;        // All files and subfolders have been retrieved.
    }
    else
    {
        throw new Exception($"Unable to query items: {msg.StatusCode}");
    }
} while (true);