REST API

The Alterations module exposes a REST API for managing alteration plans. For example, to submit a plan that modifies a variable, migrates the workflow instance to a new version and to schedule an activity, use the following request:

POST /alterations/submit HTTP/1.1
Host: localhost:5001

{
    "alterations": [
        {
            "type": "ModifyVariable",
            "variableId": "83fde420b5794bc39a0a7db725405511",
            "value": "Hello world!"
        },
        {
            "type": "Migrate",
            "targetVersion": 9
        },
        {
            "type": "ScheduleActivity",
            "activityId": "mY1rb4GRjkW3urm8dcNSog"
        }
    ],
    "workflowInstanceIds": [
        "88ce68d00e824c78a53af04f16d276ea"
    ]
}

The response wil include the Plan ID:

You can use the Plan ID to query the status of the plan:

The response will include the plan's status:

Immediate Alterations

Instead of submitting alteration plans for asynchronous execution, you can apply alterations immediately using the IAlterationRunner service. For example:

When an alteration plan is executed immediately, the alterations are applied synchronously and the results are returned. You will have to manually schedule affected workflow instances to resume execution. Use the IAlteredWorkflowDispatcher:

This will tell the workflow engine to pickup the altered workflow instances and execute them.

Extensibility

Elsa Workflows supports custom alteration types, allowing developers to define their own types and utilise them as alterations.

To define a custom alteration type, implement the IAlteration interface.

Next, implement an alteration handler that handles the alteration type.

Or, derive from the AlterationHandlerBase<T> base class to simplify the implementation.

Finally, register the alteration handler with the service collection.

Example

The following example demonstrates how to define a custom alteration type and handler.

Last updated