Share via


WorkflowClient.CreateOrReplaceAsync Method

Definition

[Protocol Method] Create or replace a workflow.

  • 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> CreateOrReplaceAsync (Guid workflowId, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateOrReplaceAsync : Guid * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateOrReplaceAsync : Guid * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateOrReplaceAsync (workflowId As Guid, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

workflowId
Guid

The workflow id.

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

content is null.

Service returned a non-success status code.

Examples

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

Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
WorkflowClient client = new WorkflowClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    triggers = new object[]
    {
        new
        {
            type = "when_term_creation_is_requested",
        }
    },
    name = "<name>",
    isEnabled = true,
    description = "<description>",
});
Response response = await client.CreateOrReplaceAsync(Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"), content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("actionDag").ToString());
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("triggers")[0].GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("isEnabled").ToString());
Console.WriteLine(result.GetProperty("description").ToString());

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

Uri endpoint = new Uri("<endpoint>");
TokenCredential credential = new DefaultAzureCredential();
WorkflowClient client = new WorkflowClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    triggers = new object[]
    {
        new
        {
            type = "when_term_creation_is_requested",
            underGlossaryHierarchy = "<underGlossaryHierarchy>",
            underCollection = "<underCollection>",
            underGlossary = "<underGlossary>",
        }
    },
    name = "<name>",
    isEnabled = true,
    description = "<description>",
    actionDag = new object(),
});
Response response = await client.CreateOrReplaceAsync(Guid.Parse("73f411fe-4f43-4b4b-9cbd-6828d8f4cf9a"), content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("actionDag").ToString());
Console.WriteLine(result.GetProperty("id").ToString());
Console.WriteLine(result.GetProperty("triggers")[0].GetProperty("type").ToString());
Console.WriteLine(result.GetProperty("triggers")[0].GetProperty("underGlossaryHierarchy").ToString());
Console.WriteLine(result.GetProperty("triggers")[0].GetProperty("underCollection").ToString());
Console.WriteLine(result.GetProperty("triggers")[0].GetProperty("underGlossary").ToString());
Console.WriteLine(result.GetProperty("createdTime").ToString());
Console.WriteLine(result.GetProperty("createdBy").ToString());
Console.WriteLine(result.GetProperty("lastUpdateTime").ToString());
Console.WriteLine(result.GetProperty("updatedBy").ToString());
Console.WriteLine(result.GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("isEnabled").ToString());
Console.WriteLine(result.GetProperty("description").ToString());

Applies to