Update a Folder's Permissions

Updates a folder's permissions.

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:

Update a folder's permissions

URI

https://bartendercloud.com/api/librarian/folders/{folderId}/permissions

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 folder. Required.

Query Parameters

None.

Example

Request body: See FolderUpdatePermissionsRequest.

Response: See FolderPermissions.

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

// Create the permissions request object.
var permissionsRequest = new FolderUpdatePermissionsRequest() {
    InheritFromFolderPermissions = false,
    Permissions = new List<FilePermissionWithIdentities>()
};

// Construct the container that includes mappings of identity types to the list of identities.
// Assume that userId is the ID of the user to whom we want to grant FolderPermission.Read and FolderPermission.List permissions.
Dictionary<IdentityType, List<Identity>> grantedTo = new Dictionary<IdentityType, List<Identity>> ();
grantedTo.Add(IdentityType.User, new List<Identity> { userId });
// Grant Read permission to the list of 'grantTo' identities.
permissionsRequest.Permissions.Add(new FolderPermissionWithIdentities() { 
   Permission = FilePermission.Read, 
   GrantedTo = grantedTo
});
// Grant List permission to the list of 'grantTo' identities.
permissionsRequest.Permissions.Add(new FolderPermissionWithIdentities() { 
   Permission = FolderPermission.List, 
   GrantedTo = grantedTo
});

HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), new Uri($"https://bartendercloud.com/api/librarian/folders/{folderId}/permissions"))
{
   Content = new StringContent(JsonConvert.SerializeObject(permissionsRequest), Encoding.UTF8, "application/json")
};

HttpResponseMessage msg = await client.SendAsync(request);
if (msg.IsSuccessStatusCode)
{
   return JsonConvert.DeserializeObject<FolderPermissions>(await msg.Content.ReadAsStringAsync());
}