API User's Guide
PowerShell: Updating attachment descriptions
Introduced in 2022.2
You can use PowerShell scripts to update the description of a particular attachment. The script below updates the description of the file file_name attached to the Incident T000030. It 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.
NOTE: To get the proper output, make sure that the ticket T000030 exists in your database and the file file_name is available; otherwise, replace the sample values with your actual IDs.
$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
$objectID = 'T000030' # object ID
$fileName = 'file_name' # attachment file name
$description = 'updated' # new attachment description
$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/Object/$objectID/Attachments?par_fields=ID&File_Name=" + [Uri]::EscapeDataString($fileName)) `
-Method GET `
-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json'; }
$attachmentId = ($htmlResponse.Content | ConvertFrom-Json).ResponseObject.Data[0]
$body = @{
'Description' = $description;
} | ConvertTo-Json
$htmlResponse = Invoke-WebRequest -Uri "$ApiUrl/Object/$objectID/Attachments/$attachmentId" `
-Method PATCH `
-Headers @{ 'authorization' = "bearer $token"; 'content-type' = 'application/json'; } `
-Body $body
$htmlResponse