Share via


ConfidentialLedgerClient.CreateOrUpdateUserAsync Method

Definition

[Protocol Method] Adds a user or updates a user's fields.

  • This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
public virtual System.Threading.Tasks.Task<Azure.Response> CreateOrUpdateUserAsync (string userId, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateOrUpdateUserAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateOrUpdateUserAsync : string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateOrUpdateUserAsync (userId As String, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

userId
String

The user id, either an AAD object ID or certificate fingerprint.

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

userId or content is null.

Service returned a non-success status code.

Examples

This sample shows how to call CreateOrUpdateUserAsync and parse the result.

TokenCredential credential = new DefaultAzureCredential();
ConfidentialLedgerClient client = new ConfidentialLedgerClient(new Uri("http://localhost:3000"), credential);

using RequestContent content = RequestContent.Create(new
{
    assignedRole = "Administrator",
});
Response response = await client.CreateOrUpdateUserAsync("<userId>", content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("assignedRole").ToString());

This sample shows how to call CreateOrUpdateUserAsync with all parameters and request content and parse the result.

TokenCredential credential = new DefaultAzureCredential();
ConfidentialLedgerClient client = new ConfidentialLedgerClient(new Uri("http://localhost:3000"), credential);

using RequestContent content = RequestContent.Create(new
{
    assignedRole = "Administrator",
});
Response response = await client.CreateOrUpdateUserAsync("<userId>", content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("assignedRole").ToString());
Console.WriteLine(result.GetProperty("userId").ToString());

Remarks

A JSON merge patch is applied for existing users

Below is the JSON schema for the request and response payloads.

Request Body:

Schema for LedgerUser:

{
  assignedRole: "Administrator" | "Contributor" | "Reader", # Required. Represents an assignable role.
  userId: string, # Optional. Identifier for the user. This must either be an AAD object id or a certificate fingerprint.
}

Response Body:

Schema for LedgerUser:

{
  assignedRole: "Administrator" | "Contributor" | "Reader", # Required. Represents an assignable role.
  userId: string, # Optional. Identifier for the user. This must either be an AAD object id or a certificate fingerprint.
}

Applies to