PowerShell Example: Run a One-Step Action that Includes a Prompt

These Powershell commands provide an example for running a One-Step™ Action using a OneStepActionRequest that provides an existing Incident and adds a Journal to it. In this One-Step Action, the contents are determined by a prompt.

# 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)" }

# Build a One-Step Action Request that will run an Incident One-Step Action
# from the Global scope that adds a Journal to a specific Incident with the
# details for the Journal being provided by a prompt
$incidentBusObId = "6dd53665c0c24cab86870a21cf6434ae"
$recordId = "9451a88b3582418263efdf4fe0a5709443f8176be6"
$oneStepId = "9451b5d71fba1b00c809b5477691ebcde8f49786cd"
$promptInput = "This journal was created by the REST API"
# Either the promptDefId or the promptName can be used to provide a value for
# the prompt. If both are provided, it will match based on the ID.
$oneStepActionRequestBody = @"
  "acquireLicense": "true",
  "busObId": "${incidentBusObId}",
  "busObRecId": "${recordId}",
  "oneStepActionStandInKey": "DefType:OneStepDef#Scope:Global#Id:${oneStepId}#Owner:${incidentBusObId}",
  "promptValues": [
      "promptDefId": "9451b5d880b9dd6497188d45d8a91fa1d9dad4856b",
      "promptName": "JournalDetailsPrompt",
      "value": "$promptInput"

$oneStepActionUri = ${baseUri} + "api/V1/runonestepaction"
$oneStepActionResponse = Invoke-RestMethod -Method POST -Uri $oneStepActionUri -Header $requestHeader -ContentType "application/json" -Body $oneStepActionRequestBody