API User's Guide

PowerShell: Retrieving object classification values (GET)

Introduced in 8.7

Updated in 2021.1

You can use PowerShell scripts to retrieve classification values of Alloy Navigator objects using a GET query. The script below retrieves a list of types for Computers. It uses using user authentication to return Computers' Type values filtered by the Rank = 2 condition, sorted by the Type field in ascending order, with no offset. These values are returned: Type, Rank.

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

$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/Dictionary?par_objectClass=Computers&par_refField=Type&par_fields=Type,Rank&par_limit=0&par_sort_asc=Type&Rank=2" `
	-Method GET `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json'; }