API User's Guide

PowerShell: Listing attachments (POST)

Introduced in 2022.2

You can use PowerShell scripts to retrieve attachments of Alloy Navigator objects using a POST query. The script below lists files attached to the Incident T000030. It uses user authentication to access Alloy Navigator and list all files attached to the Incident T000030 with their file name, file size, and created date, sorted by File Name in ascending order.

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 ticket T000030 exists in your database; otherwise, replace the sample value with your actual ID.

PowerShell
$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 -Uri "$ApiUrl/Object/T000030/Attachments" `
	-Method POST `
	-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json';  } `
	-Body @'
{
	"Fields": [
		"File_Name",
		"File_Size",
		"Created_Date"
	],
	"Sort": [
		{
		"property": "File_Name"
		}
	],
}
'@
 
$htmlResponse