How to: Manage workflows

Manage and run workflows

Now that you’ve authored the workflow and its activities in your application, you can start, terminate, and get information about the workflow using HTTP API calls. For more information, read the workflow API reference.

Manage your workflow within your code. In the OrderProcessingWorkflow example from the Author a workflow guide, the workflow is registered in the code. You can now start, terminate, and get information about a running workflow:

  1. string orderId = "exampleOrderId";
  2. string workflowComponent = "dapr";
  3. string workflowName = "OrderProcessingWorkflow";
  4. OrderPayload input = new OrderPayload("Paperclips", 99.95);
  5. Dictionary<string, string> workflowOptions; // This is an optional parameter
  6. CancellationToken cts = CancellationToken.None;
  7. // Start the workflow. This returns back a "WorkflowReference" which contains the instanceID for the particular workflow instance.
  8. WorkflowReference startResponse = await daprClient.StartWorkflowAsync(orderId, workflowComponent, workflowName, input, workflowOptions, cts);
  9. // Get information on the workflow. This response will contain information such as the status of the workflow, when it started, and more!
  10. GetWorkflowResponse getResponse = await daprClient.GetWorkflowAsync(orderId, workflowComponent, workflowName);
  11. // Terminate the workflow
  12. await daprClient.TerminateWorkflowAsync(instanceId, workflowComponent);

Manage your workflow using HTTP calls. The example below plugs in the properties from the Author a workflow example with a random instance ID number.

Start workflow

To start your workflow with an ID 12345678, run:

  1. POST http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/12345678/start

Terminate workflow

To terminate your workflow with an ID 12345678, run:

  1. POST http://localhost:3500/v1.0-alpha1/workflows/dapr/12345678/terminate

Get information about a workflow

To fetch workflow information (outputs and inputs) with an ID 12345678, run:

  1. GET http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/12345678

Learn more about these HTTP calls in the workflow API reference guide.

Next steps

Last modified February 8, 2023: Update howto-manage-workflow.md (0209168e)