Solved

Updating Asset State Field using API

  • 9 September 2022
  • 6 replies
  • 595 views

Badge

I am looking to update the Asset State field of all of the Assets in our organization using the API but haven’t been able to work it out from the documentation.

The documentation shows “asset_state_25” nested under “type_fields”. I am unclear if this _25 is required for all or if it relates to the asset_type_id that is 25 in the example. 

I’ve tested with the request body as the below but all return (400) Bad Request

$body = '{type_fields": {"asset_state_25": "Retired"}}' #documentation based
$body = '{type_fields": {"asset_state": "Retired"}}'
$body = '{type_fields": {"asset_state_2325": "Retired"}}' #asset id based
$body = '{type_fields": {"asset_state_10000652032": "Retired"}}' #asset type id based

Has anybody got some experience with this that could shed some light on how it should be formatted.

icon

Best answer by Pluck 15 September 2022, 15:51

View original

6 replies

I just ran into same issue and now finally managed to fix it. You need to find the parent asset type id. In my case the asset type structure is Hardware > Computer > laptops. So, I had to find the id for the Hardware asset type.

 

First find an asset using  https://domain.freshservice.com/api/v2/assets/id, note down the asset type id from the result. Then find the parent asset type ID using this URI https://domain.freshservice.com/api/v2/asset_types/asset_type_id

From the result note down the parent asset type id.

 

Following are my codes for the body, replace the number with the parent asset id.

     $Body = @{

    "type_fields" = @{

        "asset_state_260005" = 'Retired'

        }

    }

    $Body = $Body | ConvertTo-Json

Hi Pluck,

Yeah, I'm trying to use API's to update assets too, if you could supply your sample body text would be very helpful as you've got it to work.

Many thanks

Alan

Badge

I had a quote missing from my body after updating the asset type into the asset_state field. After correcting this I was able to post updates

 

Any chance you're able to provide a copy of what your final json body looked like? Been trying to change the asset state with the api and Powershell but no luck. 

Badge

I had a quote missing from my body after updating the asset type into the asset_state field. After correcting this I was able to post updates

Badge

Hi,


The asset_state_25 attribute refers to the asset state and not the asset type field. You can use an API asset GET request to get all the fields that correspond to your assets and then use a PUT request to update the asset. That way you will be able to update the corresponding asset state value that’s saved for your portal in the backend. The error could also be in the API call you’ve given. can you please provide us with the API call? Please refer to this article below to know more about asset API GET calls: https://api.freshservice.com/#view_an_asset
 

Regards,

Aravindsrihari B V.

Hi Aravindsrihari,

I ended up creating a ticket to try and get an answer on this they have advised the below

“With regards to the query, 25 indicates the asset parent type id. As you are aware we have different asset types in Freshservice and based on this there are multiple other sub-asset types that fall under the parent type. You can replace the value with value from you instance for parent asset type for the asset in which you are running the update asset api call.”

So running a Get call against https://***.freshservice.com/api/v2/assets/1?include=type_fields will return the asset parent type ID that is needed to be appended to “asset_state_”

Even with this response I am still unable to get the correct body and am waiting for an example from FreshService that will allow me to update the asset_state field only. I will update this once I hear back from them but if anybody has any input I’ll be glad to hear it. 

 

The API call I have tried “https://*****.freshservice.com/api/v2/assets/2325" and "https://*****.freshservice.com/api/v2/assets/2325?include=type_fields"

Userlevel 2
Badge +2

Hi,


The asset_state_25 attribute refers to the asset state and not the asset type field. You can use an API asset GET request to get all the fields that correspond to your assets and then use a PUT request to update the asset. That way you will be able to update the corresponding asset state value that’s saved for your portal in the backend. The error could also be in the API call you’ve given. can you please provide us with the API call? Please refer to this article below to know more about asset API GET calls: https://api.freshservice.com/#view_an_asset
 

Regards,

Aravindsrihari B V.

Reply