Share via


CosmosUser.UpsertPermissionAsync Method

Definition

Upsert a permission as an asynchronous operation in the Azure Cosmos service.

public abstract System.Threading.Tasks.Task<Azure.Cosmos.PermissionResponse> UpsertPermissionAsync (Azure.Cosmos.PermissionProperties permissionProperties, int? tokenExpiryInSeconds = default, Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertPermissionAsync : Azure.Cosmos.PermissionProperties * Nullable<int> * Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Cosmos.PermissionResponse>
Public MustOverride Function UpsertPermissionAsync (permissionProperties As PermissionProperties, Optional tokenExpiryInSeconds As Nullable(Of Integer) = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of PermissionResponse)

Parameters

permissionProperties
PermissionProperties

The PermissionProperties object.

tokenExpiryInSeconds
Nullable<Int32>

(Optional) The expiry time for resource token in seconds. This value can range from 10 seconds, to 24 hours (or 86,400 seconds). The default value for this is 1 hour (or 3,600 seconds). This does not change the default value for future tokens.

requestOptions
RequestOptions

(Optional) The options for the permission request RequestOptions

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

A Task containing a PermissionResponse which wraps a PermissionProperties containing the read resource record.

Exceptions

This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a permission are:

StatusCodeReason for exception
400BadRequest - This means something was wrong with the request supplied. It is likely that an id was not supplied for the new permission.

Examples

PermissionProperties permissionProperties = new PermissionProperties("permissionId", PermissionMode.All, database.GetContainer("containerId"), new PartitionKey("tenantId"))";

PermissionResponse response = await this.cosmosDatabase.GetUser("userId").UpsertPermissionAsync(permissionProperties, tokenExpiryInSeconds: 9000);

Applies to