Skip to main content

Been banging my head against this for the last couple hours and can’t seem to figure it out. Current state of the asset is “Reserved” and I want to change it to Retired. I’ve experimented and I have the below which changes the name of the Asset and that works with no issues:

$APIKey = 'myapi'
$EncodedCredentials = nConvert]::ToBase64String(6Text.Encoding]::ASCII.GetBytes(('{0}:{1}' -f $APIKey, $null)))
$HTTPHeaders = @{}
$HTTPHeaders.Add('Authorization', ('Basic {0}' -f $EncodedCredentials))

$URL = 'https://mydomain.freshservice.com/api/v2/assets/1347'

$AssetAttributes = @{}
$AssetAttributes.Add('name' , 'NewAssetNameHere')
$JSON = $AssetAttributes | ConvertTo-Json

$Params = @{

Method = 'Put'
Uri = $URL
Headers = $HTTPHeaders
ContentType = 'application/json'
Body = $JSON
}
Invoke-RestMethod @Params

 

However, I’ve tried the below to change the Asset State and that times out with a “Invoke-RestMethod : The remote server returned an error: (400) Bad Request” even though I’ve only changed one line:

 

$APIKey = 'myapi'
$EncodedCredentials = cConvert]::ToBase64String(tText.Encoding]::ASCII.GetBytes(('{0}:{1}' -f $APIKey, $null)))
$HTTPHeaders = @{}
$HTTPHeaders.Add('Authorization', ('Basic {0}' -f $EncodedCredentials))

$URL = 'https://mydomain.freshservice.com/api/v2/assets/1347'

$AssetAttributes = @{}
$AssetAttributes.Add('asset_state' , 'Retired')
$JSON = $AssetAttributes | ConvertTo-Json

$Params = @{

Method = 'Put'
Uri = $URL
Headers = $HTTPHeaders
ContentType = 'application/json'
Body = $JSON
}
Invoke-RestMethod @Params

Anyone able to point me in the direction of what exactly I’m doing wrong?

Join the Community or User Group to Participate in this Discussion

Reply