API User's Guide

PowerShell: Updating Incidents

Introduced in 8.7

Updated in 2021.1

You can use PowerShell scripts to run workflow Step Actions on Alloy Navigator objects. The script below updates the Incident T000029 using the workflow action "Add Comment" #253. It gets access to Alloy Navigator using user authentication.

Copy the script and replace the placeholders with your actual API URL and the credentials of an Alloy Navigator technician account.

NOTE: To get the proper output, make sure that the Incident T000029 and other objects exist in your database and the action #253 is available: otherwise, replace the sample values with your actual IDs.

PowerShell
$ApiUrl = 'https://API_URL'	# API URL without a trailing slash, i.e. https://example.com/api
$username = 'your_username'	# technician username
$password = 'your_password'	# technician password
 
$postParams = @{ 'grant_type' = 'password'; 'username' = $username; 'password' = $password; }
$htmlResponse = Invoke-WebRequest -UseBasicParsing -Uri "$ApiUrl/token" -Method POST -Body $postParams
$token = (ConvertFrom-Json $htmlResponse.Content).access_token
 
$htmlResponse = Invoke-WebRequest -UseBasicParsing -Uri "$ApiUrl/Object/T000029/Action/253" `
	-Method POST `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json';  } `
	-Body @'
{
	"Activity.Time_Spent": 90,
	"Comment": "Updated via the API"
}
'@
 
$htmlResponse