Powershell API Call Updating Type Fields

I am currently working on a PowerShell script that we’ll be using to process assets in FreshService. Two of the fields I’d like to update in particular are the asset_state and last_audit_date fields.

I did pull the appropriate ID for the asset_type and saw that these are two fields that are included in the Update Assets API call example.

$parameters = @{

        asset = @{

            name = "Super Test Laptop2"
            description = "Test Description 1"
            user_id = $null
            location_id = $In_IT_Cabinet
            assigned_on = "$today_date"
            updated_at =  "$today_date"
            type_fields = @{
                asset_state_11000923165 = "In Stock"
                last_audit_date_11000923165 = "$today_date"

    invoke-RestMethod -URI "https://novinium.freshservice.com/api/v2/assets/$display_id" -Headers $Header -ContentType "application/json" -Method Put -Body (ConvertTo-Json $parameters)

When I pass in my request using the type_fields array I am getting a 400 bad request return. If I remove the type_fields array it works just fine.

Any help on this would be greatly appreciated!

An update on my end.

I did some additional testing this morning and realized that the update_at value was the one that was causing me to receive the 400 error message. I thought I had been using that previously but it was actually the assigned_on variable.

Once I commented that line out of my script the type_fields array passed just fine.

1 Like

Oh wow! Nice! Kind of what I’m looking for as proof of concept. I’m hoping to build a webpage for IT Staff only that allows us to login to retrieve a user’s list of assents, then click a button next to each to update their “Last Audit” date. I’ve been asking for this for a while now from Freshservice and it gets no where to make asset management even easier when performing a user audit. Guess I’ll have to dust my coding skills off to do it myself. UGH!