Complete Task via Web Service

Web Service Overview

All web services which are provided by the FireStart server can be found under https://<server>:<port>/api/swagger/ui/index.

Execution ID 

The execution ID one of the system fields among the workflow variables. But these system fields are only shown when Show system fields is checked. 

complete-task-via-web-service-2017-12-11

Task Element ID 

To find the task element ID, right-click the task element and choose Edit event, and switch to the Menu External event. Now the task element ID is displayed in the textbox with the label Your event elementID is.

complete-task-via-web-service-2017-12-11-2

complete-task-via-web-service-2018-02-20-1

Example: Complete Task via PowerShell

In this example, you will learn how to complete a task via a PowerShell script. Keep in mind, that the authentication of the web service will be done with NTLM. The authenticated user for FireStart is the same user who completes the task. In the following example, the windows user was authorized sufficiently, which means that "-UseDefaultCredential" could be used in this case.

Call


# Name and port of the FireStart server.

$server = "<server>:<port>"




# Element id of the task to be completed.

$taskElementId = "<taskElementId>" 




# Execution id of the workflow.

$executionId = "<executionId>"




$id = Get-TaskIdFromExecution -server $server -executionId $executionId -elementId $taskElementId 

Finish-ConfirmationTask -server $server -executionId $executionId -id $id 

Read Task ID


# Get the task id for a specific task in an execution.

function Get-TaskIdFromExecution()

{

    param

    (

        [string]$server,

        [string]$executionId,

        [string]$elementId

    )

    $url = 'https://' + $server + '/api/processinstance/' + $executionId

    $result = Invoke-RestMethod -Uri $url -UseDefaultCredential

  

    return $result.ExecutionInstances | Where-Object {$_.TrackingId -eq $elementId} | Select -Expand Id

}

Complete Task


# Finish a read only task. No values will be written to business entities.

function Finish-ConfirmationTask()

{

    param

    (

        [string]$server,

        [string]$executionId,

        [string]$id

    )




    # Get some values needed to complete the task

    $confirmation = Invoke-RestMethod -Uri ('https://' + $server + '/api/task/' + $id)

                                      -UseDefaultCredentials




    $buildNumber = Invoke-RestMethod -Uri ('https://' + $server + '/api/clientupdate/build')

                                      -UseDefaultCredentials




  

    FinishTask -server $server -executionId $executionId -id $id -taskId $confirmation.TaskId

        -returnData "<FormData xmlns=`"http://www.prologics.at/form`" Build=`"$buildNumber`"></FormData>"

}




function FinishTask()

{

    param

    (

        [string]$server,

        [string]$executionId,

        [string]$id,

        [string]$taskId,

        [string]$returnData

    )

    $url = 'https://' + $server + '/api/task/' + $taskId




    $body = 

    @{

        Id = $id

        TaskId = $taskId

        ExecutionId = $executionId

        State = "Complete"

        Priority = "High"

        Progress = 100

        ReturnData = $returnData

        WorkDuration = 0

        EndDate = [DateTime]::UtcNow.ToString('o')

    }

    

    Invoke-RestMethod -Uri $url -Method Put -ContentType "application/json" -Body ($body | ConvertToJson)

        -UseDefaultCredential

}