PowerShell Example: Run a One-Step Action

These Powershell commands provide an example of running a simple, unassociated One-Step™ Action that creates a Business Object using a StandInKey.

# Set server login variables
$serverName = "your server"
$apiKey = "your client id"
$userName = "CSDAdmin"
$password = "CSDAdmin"
$baseUri = "http://${serverName}/CherwellAPI/"

# Get an access token
$tokenUri = $baseUri + "token"
$authMode = "Internal"
$tokenRequestBody =
@{
    "Accept" = "application/json";
    "grant_type" = "password";
    "client_id" = $apiKey;
    "username" = $userName;
    "password"= $password
}
$tokenResponse = Invoke-RestMethod -Method POST -Uri "${tokenUri}?auth_mode=${authMode}&api_key=${apiKey}" -Body $tokenRequestBody

$requestHeader = @{ Authorization = "Bearer $($tokenResponse.access_token)" }

# Run a simple One-Step Action from the Global scope that requires no input
# Note the StandInKey is URL encoded, so ':' becomes '%3A' and '#' becomes '%23'
$standInKey = "DefType%3AOneStepDef%23Scope%3AGlobal%23Id%3A9451b5b6d294dfe8a1bb054dec9f4bbb1c07460a4a"
$oneStepActionUri = $baseUri + "api/V1/runonestepaction/standinkey/${standInKey}"
$oneStepActionsResponse = Invoke-RestMethod -Method GET -Uri $oneStepActionUri -ContentType application/json -Header $requestHeader