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 POST 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.

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/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