API User's Guide

PowerShell: Submitting Service Requests

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 creates a Service Request for the Service Catalog Item SCI000005using the workflow action "Submit Request" #131. 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 item SCI000005 and other objects exist in your database and the action #131 is available; otherwise, replace the sample values with your actual IDs.

PowerShell
$ApiUrl = 'http://API_URL'	# API URL without trailing /, i.e. http://example.com/api
$username = 'your_username'	# technician username
$password = 'your_password'	# technician password
 
$postParams = @{ 'grant_type' = 'password'; 'username' = $username; 'password' = $password; }
$htmlResponse = Invoke-WebRequest -Uri "$ApiUrl/token" -Method POST -Body $postParams
$token = (ConvertFrom-Json $htmlResponse.Content).access_token
 
$htmlResponse = Invoke-WebRequest -Uri "$ApiUrl/Object/SCI000005/Action/131" `
	-Method POST `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json';  } `
	-Body @'
{
	"Organization": "O000003",
	"Requester": "PN000022",
	"Request for": "PN000016",
	"Request Details": "<p>Created via the API</p>",
	"Urgency": "1 - Immediate",
	"Impact": "3 - Single Person"
}
'@
 
$htmlResponse