API & Client
Comprehensive guide to interacting with Elsa Server programmatically via HTTP APIs and the elsa-api-client library, covering workflow publishing, instance management, bookmarks, and resilience pattern
Executive Summary
This guide covers how to interact with Elsa Workflows programmatically using:
HTTP APIs — Direct REST calls to Elsa Server endpoints
elsa-api-client — Official .NET client library for type-safe API interactions
When to Choose Direct HTTP vs Client Library
Direct HTTP
Polyglot teams, non-.NET clients, simple integrations
Language-agnostic, minimal dependencies
Manual serialization, no type safety
elsa-api-client
.NET applications, complex workflows, production systems
Type-safe, automatic serialization, resilience patterns
.NET-only, additional dependency
Recommendation: For .NET applications, prefer elsa-api-client for type safety and built-in conveniences. For non-.NET clients or simple webhook integrations, use direct HTTP calls.
Code Reference: src/clients/Elsa.Api.Client/ — Official API client implementation.
Architecture Overview
Core Concepts
Elsa's API is organized around three primary entities:
Workflow Definitions
Blueprint templates for workflows
/api/workflow-definitions
Workflow Instances
Running or completed executions
/api/workflow-instances
Bookmarks
Suspension points for workflow resume
/api/bookmarks
High-Level Workflow Lifecycle
Design — Create workflow definition (via Studio or programmatically)
Publish — Activate the definition for execution
Instantiate — Create a new workflow instance
Execute — Run activities until completion or suspension
Suspend (Bookmark) — Workflow pauses at blocking activity, creates bookmark
Resume — External event triggers bookmark, execution continues
Complete — Workflow finishes with success or fault status
Code Reference: src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs — Contains CreateBookmark() for suspending workflows.
Authentication & Identity
Elsa Server supports multiple authentication mechanisms. For comprehensive security guidance, see the Security & Authentication Guide (DOC-020).
Quick Reference
Bearer Token (curl)
API Key (curl)
elsa-api-client Configuration
Code Reference: src/clients/Elsa.Api.Client/Extensions/ServiceCollectionExtensions.cs — Client registration extensions.
Publishing Workflow Definitions
Using elsa-api-client (C#)
The client library provides a type-safe way to create and publish workflow definitions.
Key Properties:
DefinitionId
Unique identifier for the workflow definition
Version
Version number (increments with each publish)
Root
The root activity of the workflow
Options.CommitStrategyName
How often workflow state is persisted (see DOC-021)
Options.ActivationStrategyType
Controls how new instances are created (e.g., Singleton, Default)
Options.AutoUpdateConsumingWorkflows
Whether to update workflows that reference this one
Code Reference: src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Models/WorkflowOptions.cs
See publish-workflow.cs for a complete example.
HTTP Variant (POST)
Response (Success - 201 Created):
Versioning & Publishing Semantics
Draft vs Published
Workflow definitions have two states:
Draft
Work-in-progress definition
No
Published
Active, executable version
Yes
Multiple versions can exist, but only one version is the "latest published" version at any time.
Publishing Options
When saving a workflow definition, set Publish = true to immediately publish:
AutoUpdateConsumingWorkflows
When set to true, workflows that reference this definition (via Dispatch Workflow activity) will automatically use the new version:
Code Reference: src/modules/Elsa.Workflows.Core/Models/WorkflowOptions.cs
Activation Strategies
Control how new workflow instances are created:
Default
Each trigger creates a new instance
Singleton
Only one running instance per definition
See the documentation on Activation Strategies in the main Elsa docs for detailed guidance.
Code Reference: src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Models/WorkflowOptions.cs — ActivationStrategyType property.
Starting / Instantiating Workflows
Using elsa-api-client (C#)
See start-workflow.cs for a complete example.
HTTP Variant (POST)
Response (Success - 200 OK):
Key Parameters
definitionId
ID of the workflow definition to start
Yes
correlationId
External identifier for correlation
No
input
Dictionary of input values
No
versionOptions
Which version to run (Latest, Published, Specific)
No
Note:
TriggerWorkflowsOptionsis obsolete. Use theStartWorkflowRequestpattern shown above for creating new workflow instances.
Code Reference: src/clients/Elsa.Api.Client/Resources/WorkflowInstances/ — Instance management models.
Querying Workflow Definitions & Instances
Filtering Workflow Instances
The API supports filtering by status, correlationId, definitionId, and version with pagination.
Using elsa-api-client (C#)
See query-workflows.cs for a complete example.
HTTP Variant (curl)
Query Parameters
status
Filter by workflow status (Running, Suspended, Finished, Faulted)
Enum
correlationId
Filter by correlation ID
String
definitionId
Filter by workflow definition ID
String
version
Filter by specific version
Integer
page
Page number (0-indexed)
Integer
pageSize
Number of results per page (default: 25, max: 100)
Integer
Bookmarks & Resuming
How Bookmarks Work
Bookmarks are created when a workflow reaches a blocking activity (e.g., waiting for HTTP callback, human approval, or external event). The workflow suspends until resumed via the bookmark.
Code Reference: src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs — CreateBookmark() method.
Bookmark Creation
Activities create bookmarks using ActivityExecutionContext.CreateBookmark():
Stimulus Hashing
Bookmarks are matched using a deterministic hash based on:
Activity type name
Stimulus payload data
This allows the runtime to efficiently find matching bookmarks without knowing the instance ID.
Code Reference: src/modules/Elsa.Workflows.Core/Bookmarks/ — Stimulus hashing implementation (e.g., StimulusHasher).
Resuming Workflows
Token-Based Resume (URL)
HTTP triggers generate tokenized URLs for easy resumption:
Code Reference: src/modules/Elsa.Http/Extensions/BookmarkExecutionContextExtensions.cs — GenerateBookmarkTriggerUrl method.
Stimulus-Based Resume
Resume by providing the stimulus payload directly:
See resume-bookmark.curl.md for complete examples.
elsa-api-client Resume
Resume Flow & Locking
The WorkflowResumer service:
Acquires a distributed lock on the workflow instance
Loads the workflow state from the database
Finds the matching bookmark
Resumes execution from the bookmarked activity
Burns (deletes) the bookmark if
AutoBurn = true
Code Reference: src/modules/Elsa.Workflows.Runtime/Services/WorkflowResumer.cs — Resume logic and locking.
Security Note
Tokenized resume URLs should be treated as secrets:
Use HTTPS to prevent interception
Tokens expire when the bookmark is burned or workflow is cancelled
See Security & Authentication Guide (DOC-020) for token security best practices
Incidents & Retry / Resilience
Resilience Strategies
Elsa supports configuring resilience strategies for activities to handle transient failures. The exact API for configuring resilience may vary by version.
Setting a Resilience Strategy (Conceptual Pattern)
The following example demonstrates a conceptual pattern for configuring resilience. Consult the current Elsa documentation and source code for the actual API in your version:
See resilience-strategy.cs for additional patterns and considerations.
Note: The resilience configuration API is evolving. Check the
src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Models/directory in elsa-core for current extension methods and models.
Handling Incidents
When activities fail, Elsa creates incidents. Query instance state to check for faults:
For incident configuration and strategies, see the main documentation on incidents in the Operate Guide.
Commit Strategies
Commit strategies control when workflow state is persisted to the database. This affects durability and performance.
Selecting a Strategy
When creating a workflow definition, specify the commit strategy:
Available Strategies
WorkflowExecuted
Commits after workflow completes
High throughput, short workflows
ActivityExecuted
Commits after each activity
Maximum durability
Periodic
Commits at regular intervals
Long-running workflows
For detailed guidance on commit strategies and performance tuning, see Performance & Scaling Guide (DOC-021).
Code Reference: src/modules/Elsa.Workflows.Core/CommitStates/CommitStrategiesFeature.cs — Strategy registration.
Pagination & Performance
Pagination Parameters
All list endpoints support pagination:
page
Zero-indexed page number
0
-
pageSize
Results per page
25
100
Example with Pagination
Performance Recommendations
Use Server-Side Filtering: Always filter on the server rather than fetching all results and filtering client-side.
Limit Page Size: Use the smallest page size that meets your needs to reduce response time and memory usage.
Avoid Large Instance Graphs: When querying instances, request only summary data unless you need the full execution history.
Consider Field Selection (Future): Future versions may support field selection to reduce payload size. Check release notes for updates.
Error Handling & Troubleshooting
Common HTTP Status Codes
200 OK
Success
-
201 Created
Resource created
-
400 Bad Request
Validation error
Missing required field (e.g., root activity), malformed JSON
401 Unauthorized
Authentication failed
Invalid or expired token
404 Not Found
Resource not found
Definition ID doesn't exist
409 Conflict
Publish conflict
Version conflict during concurrent publish
410 Gone
Resource expired
Bookmark already consumed or expired
Validation Errors (400)
Bookmark Not Found (404/410)
Common causes:
Bookmark already burned (consumed)
Workflow instance was cancelled
Token expired or invalid
Resolution:
Verify the workflow instance still exists and is suspended
Check if the bookmark was already consumed
Verify the stimulus payload matches exactly what the bookmark expects
Troubleshooting Checklist
Check logs for detailed error messages
Verify authentication with a simple GET request
Validate JSON syntax before sending
Check workflow state via instance query
Review bookmark existence in database
For comprehensive troubleshooting, see Troubleshooting Guide (DOC-017).
Best Practices Summary
Correlation IDs
Use correlation IDs for multi-event workflows to track related activities
Choose meaningful, unique identifiers (e.g., order ID, customer ID)
Query by correlation ID for efficient instance lookup
Idempotent Resume Handlers
Design resume handlers to be idempotent (safe to call multiple times):
Commit Strategy Selection
Choose commit strategy based on your durability vs throughput requirements:
High throughput, short workflows
WorkflowExecuted
Long-running, must not lose progress
ActivityExecuted
Balanced for most use cases
Periodic
Client Instrumentation
For custom metrics and monitoring:
User-defined metrics for throughput, latency, error rates
Built-in tracing via Elsa.OpenTelemetry for workflow execution visibility
See Performance & Scaling Guide (DOC-021) for observability patterns.
General Recommendations
Prefer elsa-api-client for .NET applications
Handle transient failures with retry policies
Use HTTPS for all API calls
Paginate results to avoid memory issues
Monitor workflow health via status queries
Clean up completed instances via retention policies
Example Files
publish-workflow.cs — Create and publish a workflow definition
start-workflow.cs — Start a workflow instance with correlation and input
query-workflows.cs — Query instances with filtering and pagination
resume-bookmark.curl.md — Resume workflow via token or stimulus
resilience-strategy.cs — Configure resilience for activities
Source File References — elsa-core source paths for grounding
Related Documentation
Security & Authentication Guide (DOC-020) — Authentication, tokenized URLs, security
Performance & Scaling Guide (DOC-021) — Commit strategies, observability
Persistence Guide (DOC-022) — Database configuration
Troubleshooting Guide (DOC-017) — Diagnosing common issues
Clustering Guide (DOC-015) — Distributed deployment
Last Updated: 2025-11-28
Last updated