Running Workflows
There are multiple ways to run a workflow:
Using Elsa Studio.
Using a trigger, such as HTTP Endpoint.
Using Dispatch Workflow Activity
Using the Elsa REST API.
Using the Elsa library.
In this guide, we will see an example of each of these methods.
Before you start
For this guide, you will need the following:
An Elsa Server project
An Elsa Studio instance
Running Workflows via REST API
The Elsa Server exposes REST API endpoints that allow you to execute workflows programmatically. This is useful for integrating workflows into external applications or services.
Execute a Workflow by Definition ID
To execute a workflow by its definition ID, send a POST request to the following endpoint:
Example using cURL
Example using HTTPie
Request Body Parameters
input(optional): A dictionary of input values to pass to the workflowcorrelationId(optional): A correlation ID to associate with the workflow instancename(optional): A custom name for the workflow instancetriggerActivityId(optional): The ID of a specific trigger activity to start fromversionOptions(optional): Options for selecting the workflow version
Sample Response
Synchronous vs Asynchronous Execution
The Elsa Server REST API supports two execution modes:
Synchronous Execution (/execute endpoint):
The HTTP request waits for the workflow to complete before returning a response
Use this when the workflow is designed to return a result immediately (e.g., HTTP workflows with response activities)
The response includes the final workflow state and any output values
Timeout considerations: Long-running workflows may exceed HTTP timeout limits
Asynchronous Execution (/dispatch endpoint):
The HTTP request returns immediately after queuing the workflow for execution
Use this for long-running workflows or fire-and-forget scenarios
The response includes the workflow instance ID for later status queries
Recommended for workflows that don't need to respond synchronously
Example: Synchronous Execution
Example: Asynchronous Execution (Fire-and-Forget)
Authentication
The REST API requires authentication. The Authorization header value depends on your authentication configuration:
Common Authentication Schemes:
API Key Authentication (most common in Elsa Server):
Bearer Token Authentication (JWT):
Basic Authentication:
Obtaining API Keys
The method for obtaining API keys depends on your Elsa Server setup:
Elsa Server with Identity: Use the identity endpoints to register users and generate API keys
Custom Authentication: Refer to your organization's authentication provider
Development/Testing: API keys may be pre-configured in
appsettings.jsonor generated via Elsa Studio
For detailed information about configuring authentication, setting up API keys, and implementing custom authentication schemes, see the Security and Authentication Guide.
Important: The
Authorizationheader examples in this guide useApiKey YOUR_API_KEYas a placeholder. Replace this with your actual authentication scheme and credentials based on your Elsa Server configuration. The authorization format and credentials depend on how authentication is configured in your Elsa Server instance.
Troubleshooting REST API Execution
This section covers common issues when executing workflows via the REST API.
Issue: Workflow Starts but HTTP Response Activity Not Reached
Symptoms:
You call the
/executeendpoint to start an HTTP workflowThe API returns immediately with a workflow instance ID
The workflow starts executing but never reaches the HTTP Response activity
The HTTP client receives an incomplete or unexpected response
Possible Causes:
Wrong Endpoint: Using
/dispatchinstead of/executeSolution: Use the
/executeendpoint for synchronous HTTP workflows that need to return a response. The/dispatchendpoint is fire-and-forget and returns immediately without waiting for workflow completion.
Workflow Not Designed for Synchronous Execution:
The workflow may contain blocking activities (delays, waiting for external events) that suspend execution
Solution: Ensure the workflow completes synchronously without suspension. Remove or reconfigure blocking activities for synchronous HTTP workflows.
HTTP Response Activity Misconfigured:
The HTTP Response activity may not be connected properly in the workflow graph
Output expressions may be incorrect or throw exceptions
Solution: Verify the workflow design in Elsa Studio. Check that the HTTP Response activity is on the execution path and its properties are correctly configured.
Workflow Faults Before Reaching Response Activity:
An activity before the HTTP Response activity throws an exception
Solution: Check the workflow execution logs and incidents for errors. Use the Troubleshooting Guide to diagnose faulted activities.
Timeout Issues:
The workflow takes too long and the HTTP client times out
Solution: Increase the HTTP client timeout, or redesign the workflow to complete faster. For long-running workflows, use the
/dispatchendpoint and implement a callback or polling mechanism.
Missing HTTP Workflow Configuration:
Elsa Server may not be configured to handle HTTP workflows properly
Solution: Ensure
UseHttp()is called in the Elsa configuration and that the HTTP middleware is registered:
Debugging Steps
Check Workflow Execution Status:
Review Execution Logs:
Check the
WorkflowExecutionLogtable or use Elsa Studio to view the workflow execution historyLook for activities that faulted or didn't execute
Verify Workflow Design:
Open the workflow in Elsa Studio
Ensure the HTTP Response activity is reachable from the HTTP Endpoint trigger
Test the workflow in the Studio designer
Enable Detailed Logging:
Test with a Simple Workflow:
Create a minimal workflow: HTTP Endpoint → HTTP Response
If this works, incrementally add activities to identify the problematic step
For more troubleshooting guidance, see the Troubleshooting Guide.
Running Workflows via the Library
You can also run workflows programmatically from your .NET application using Elsa's API client or by directly using the workflow runtime services.
Using IWorkflowRunner
The IWorkflowRunner service executes workflows directly in-process. This is useful for short-lived workflows that don't require background execution.
Using IWorkflowRuntime (New Client API)
For running workflows by definition ID with input parameters, use the new IWorkflowRuntime client API:
Using IWorkflowRuntime (Legacy API - Obsolete)
Note: The following API is marked as obsolete in Elsa 3.2+. Use the new client API shown above instead.
Comparison: IWorkflowRunner vs IWorkflowRuntime vs IWorkflowDispatcher
Understanding when to use each workflow execution service is important for designing your application architecture:
Execution Model
Synchronous, in-process
Asynchronous with persistence
Queue-based dispatching
Use Case
Unit tests, simple workflows
Most application scenarios
Background processing, distributed systems
Persistence
No (in-memory only)
Yes
Yes (via runtime)
State Management
Transient
Full state tracking
Managed by runtime
Resumption Support
No
Yes
Yes
Bookmark Support
Limited
Full
Full
Distributed Execution
No
Limited
Yes
API Complexity
Simple
Moderate
Advanced
Typical Namespace
Elsa.Workflows
Elsa.Workflows.Runtime
Elsa.Workflows.Runtime
When to Use Each
Use IWorkflowRunner when:
Writing unit tests for workflow logic
Executing simple, short-lived workflows that don't need persistence
Running workflows entirely in-process without external dependencies
You need immediate, synchronous execution
Use IWorkflowRuntime when:
Building applications that need workflow persistence and state management
You need to resume workflows after suspension (bookmarks, delays)
You want the high-level client API for workflow operations
Most production scenarios with standard execution requirements
Use IWorkflowDispatcher when:
Implementing custom workflow execution strategies
Building queue-based or message-driven workflow systems
Creating distributed workflow architectures across multiple nodes
You need fine-grained control over workflow dispatching and execution
For more details on the dispatcher architecture, see the Workflow Dispatcher Guide.
Last updated