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