API User's Guide

PowerShell: Retrieving object classification values (POST)

Introduced in 8.7

Updated in 2021.1

You can use PowerShell scripts to retrieve classification values of Alloy Navigator objects using a POST query. The script below retrieves a list of statuses for Incidents. It uses user authentication to return all Incidents' Status values, with no offset, sorted by Rank in ascending order.

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

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/Dictionary" `
	-Method POST `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json';  } `
	-Body @'
{
	"refField": "Status",
	"objectClass": "Incidents",
	"Fields": [
		"Status",
		"Rank"
	],
	"Sort": [
		{
		"property": "Rank",
		"direction": "asc"
		}
	],
	"Limit": 0,
	"Offset": 0
}
'@
 
$htmlResponse