I am making a Powershell script to add hardware items from a spreadsheet to Solarwinds Service Desk Assets.
In making my test script, I try to write a test item via POST request to the other_assets.json with the following script, but I receive a 422 error. Can you please help verify I am providing the correct input?
—
$postBody = [pscustomobject]@{
'name' = "Cisco Switch-Old-Test"
'description' = "Test Item"
'site' = @{
'name' = ""
}
'department' = @{
'name' = ""
}
'site_id' = ""
'department_id' = ""
'asset_id' = ""
'asset_type' = @{
'name' = "Switch"
}
'status' = @{
'name' = "active"
}
'manufacturer' = "Cisco"
'ip' = "0.0.0.0"
'model' = "Catalyst 3560G 48 Port PoE+"
'serial_number' = "FOC14564Y86"
'user' = @{
'email' = "cameronr@calgary -convention.com"
}
'owner' = @{
'email' = "cameronr@calgary -convention.com"
}
'custom_fields_value' = @{
'custom_fields_value' = @{
'name' = ""
}
}
} | ConvertTo-Json
$parameters = @{
'Method' = "POST"
'Uri' = "https://api.samanage.com/other_assets.json"
Headers = @{
'X-Samanage-Authorization' = "Bearer <REDACTED>"
'Accept' = "application/vnd.samanage.v2.1+json"
'Content-Type' = "application/json"
}
'Body' = $postBody
}
$AssetList = Invoke-RestMethod @parameters
Write-Output $AssetList