API User's Guide

PowerShell: Retrieving objects (GET)

Introduced in 8.7

Updated in 2021.1

You can use PowerShell scripts to retrieve information about Alloy Navigator objects using a GET query. The script below retrieves a list of Work Orders. It returns the first five Work Orders, containing the word laptop and sorted by the Type field in ascending order, without an offset. These field values are returned: Ticket, Summary. The script 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.

$ApiUrl = 'https://API_URL'	# API URL without a trailing slash, i.e. https://example.com/api
$username = 'your_username'	# technician's username
$password = 'your_password'	# technician's 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/Work Orders/?par_fields=Ticket,Summary&par_limit=5&par_offset=2&par_sort_asc=Ticket&par_search_text=laptop" `
	-Method GET `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json'; }

$htmlResponse