List Items by Folder or File Path

Lists the files and subfolders that are contained in the target folder by using the folder or file path. Only direct child files and folders are returned.

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 or file path

URI

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

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

path

Type: String

Specifies the path of the requested file or folder. Required.

 

Comment: The {path} parameter must be single-URL encoded, and the path must start with the "librarian://{spaceName}/" prefix. Replace {spaceName} with the name of the target space (such as Main or $temp).

For example, the actual path for the "My Folder" folder in the Main space is as follows: 

librarian://Main/My Folder/

The URL-encoded {path} parameter is as follows:

librarian%3A%2F%2FMain%2FMy%20Folder%2F

The full URI would resemble the following: 

https://bartendercloud.com/api/librarian/items/path/librarian%3A%2F%2FMain%2FMy%20Folder%2F

Query Parameters

None.

Example

Request body: See ItemsByPathRequest.

Response: See ItemsByPath.

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

var itemsRequest = new ItemsByPathRequest() {
    VersionMajor = 1,        // Target version 1.0 of the file.
    VersionMinor = 0,
    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/path/{path}"),
        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<ItemsByPath>(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);