Question

Updating Assets using Powershell

  • 22 April 2021
  • 5 replies
  • 400 views

Hello,

I’m trying to bulk update assets in our Freshservice with "warranty_expiry_date" from HP and hitting two main problems. One of them is specific to powershell, the second is quite general regarding how asset properties are structured. Hoping someone can help?

1) When checking the documentation for updating assets, in the sample code the properties in the "type_fields" section has the suffix "_25", like "product_25". Where does the "_25" come from? What’s that ID doing there? It doesn’t seem to be the ID of the asset and I can’t find any information where it comes from? When checking my own environment I have "_26000456017" and not "_25". But how can I programatically know what to have there when updating the asset if I don’t know what it’s supposed to be? Or is it the ID of the Freshservice instance, in which case it should be the same for all assets (which it appears to be)


2) When doing this using powershell I'm getting "415 - Unsupported media type" which is the general error for "invalid JSON". But my JSON looks ok. I don't know if there are any fields that are "required" since the documentation doesn’t detail anything, I thought just posting the asset ID and name would be sufficient but I don't know why I'm getting the error?
My powershell looks like this:

$FDApiKey="[our API key which I don't want to type here]"
$pair = "$($FDApiKey):$($FDApiKey)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$FDHeaders = @{ Authorization = $basicAuthValue }
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
$URL = "https://[ourdomain].freshservice.com/api/v2/assets"
$AssetAttributes = ""
$AssetAttributes = @{}
$AssetAttributes.Add('id', '26000338114')
$AssetAttributes.Add('name', '5CD9516D60')
$AssetAttributes.Add('asset_tag', 'ASSET-2480')
$AssetAttributes = @{'asset' = $AssetAttributes}
$JSON = $AssetAttributes | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri $URL -Headers $FDHeaders -Body $JSON

But nope :(
 

I’m not a developer used to JSON/Curl so I may have missed something obvious here :(


5 replies

have you solve this issue? face same issue related game project of APK...

 

Unfortunately no I haven’t. And even more unfortunately, Freshservice wasn’t that helpful since they don’t really seem to like Powershell and noone there could help me either.

So I ended up exporting everything to Excel CSV and matching everything there, exporting to CSV that I then imported to Fresh so it updated the assets properly.

oky thank you soo much i was worried client project of apks in this matter but i found another way 

Userlevel 4
Badge +6

Hi @stoff75,
 

Greetings!

  1. 25 in the API documentation refers to the asset_type ID. You can fetch the list of asset types and their respective IDs for your account by calling this API: https://domain.freshservice.com/api/v2/asset_types?per_page=100

  1. We have a few sample PowerShell codes to call our REST APIs mentioned here: https://support.freshservice.com/en/support/discussions/topics/312085

You may be getting this error as the ‘'Content-Type'attribute’ is missing in the headers. Could you add it to your PowerShell script and check?

"Content-Type" =  “application/json”

 

Please try and let us know if the issue persists.

 

Warm Regards,

Sanofar
Team Freshservice

oky thank you soo much i was worried client project of mod apk in this matter but i found another way 

For free APK game projects, you can search on free game websites.

Reply