Execute a flow thru the OO API by using PowerShell code

  • KM03134345
  • 02-Apr-2018
  • 02-Apr-2018

This document has not been formally reviewed for accuracy and is provided "as is" for your convenience.

Summary

This KB shows the code that can be used to execute a flow consuming the OO API with PowerShell.

Question

If the requirement is the execution of a flow thru the OO API by using PowerShell code, you can use the code below as a template and adjust it to the needs.

Answer

The code below triggers 3 flows thru PowerShell by consuming the OO API:

 

$username = "internal\testAPI"

$password = "testAPI"

$pair = "${username}:${password}"

$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)

$base64 = [System.Convert]::ToBase64String($bytes)

$basicAuthValue = "Basic $base64"

 

$executeHeaders = @{

    "Authorization" = $basicAuthValue

    "Content-Type" = "application/json"

    "Accept" = "application/json"

}

 

$json = '{"flowUuid":"":"<the flow UUID>"}'

try{

    $response = Invoke-RestMethod -Method POST -Uri "https://localhost:<port>/oo/rest/v2/executions/" -Headers $executeHeaders -Body $json -TimeoutSec 10

    write-host "$json - $response"

}

catch {

    $exceptionDetails1 = $_.Exception

    Write-Host "Error Invoking RestMethod $executeurl "

    Write-Host $exceptionDetails1

    exit 1002

}

 

$json = '{"flowUuid":"":"<the flow UUID>"}'

try{

    $response = Invoke-RestMethod -Method POST -Uri "https://localhost:<port>/oo/rest/v2/executions/" -Headers $executeHeaders -Body $json -TimeoutSec 10

    write-host "$json - $response"

}

catch {

    $exceptionDetails1 = $_.Exception

    Write-Host "Error Invoking RestMethod $executeurl "

    Write-Host $exceptionDetails1

    exit 1002

}

 

$json = '{"flowUuid":"<the flow UUID>"}'

try{

    $response = Invoke-RestMethod -Method POST -Uri "https://localhost:<port>/oo/rest/v2/executions/" -Headers $executeHeaders -Body $json -TimeoutSec 10

    write-host "$json - $response"

}

catch {

    $exceptionDetails1 = $_.Exception

    Write-Host "Error Invoking RestMethod $executeurl "

    Write-Host $exceptionDetails1

    exit 1002

}