Solved

Updating Asset State Field using API

  • 9 September 2022
  • 3 replies
  • 151 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

3 replies

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.

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"

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

Reply