API User's Guide

PowerShell: Creating Incidents

Introduced in 8.7

Updated in 2021.1

You can use PowerShell scripts to create Alloy Navigator objects via workflow "Create" workflow actions. The script below creates an Incident using the action "Submit a new Technical Issue" #231. It gets access to Alloy Navigator using user authentication.

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

NOTE: To get the proper output, make sure that the workflow action #231 is available to the technician account and the referenced Person and classification values exist in your database. Otherwise, replace the sample values with your actual Action ID and field values.

$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" `
	-Method POST `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json';  } `
	-Body @'
{
	"ActionId": 231,
	"Fields": {
		"Requester": "PN000022",
		"Summary": "Created via the API",
		"Description": "<p>This incident was created using the API.</p>",
		"Urgency": "2 - Moderate",
		"Impact": "3 - Single Person"
	}
}
'@

$htmlResponse

In the script:

  • https://API_URL is the Alloy Navigator API URL without a trailing slash.

  • your_username and your_password are the credentials of a technician account authorized to run the Create Action.

  • 231 is the ID of the workflow Create Action used to create the Incident.

  • PN000022 is the identifier of the Person record used as the Requester.

  • 2 - Moderate and 3 - Single Person are classification values available in the sample environment.

Replace the sample Action ID and field values with values from your Alloy Navigator configuration. The field names must correspond to fields used by the selected Create Action. For reference fields, specify the identifier or name of an existing object. For classification fields, specify the display value exactly as it appears in Alloy Navigator.