Asset Creation via API V2

I am trying to create an asset via the v2 API and I am getting stuck with the asset_type_id. I have confirmed the asset type id is correct by running:

curl -v -u apikey:apikey -H "Content-Type: application/json" -X GET 'https://domain.freshservice.com/api/v2/asset_types'

That gives me the asset type of Laptop which ID is 13000142404. I can double verify this by running:

curl -v -u apikey:apikey -H "Content-Type: application/json" -X GET 'https://domain.freshservice.com/api/v2/asset_types/13000142404'

That returns:

{“asset_type”:{“id”:13000142404,“name”:“Laptop”,“description”:"",“parent_asset_type_id”:13000142387,“visible”:true,“created_at”:“2020-12-31T19:46:39Z”,“updated_at”:“2020-12-31T19:46:39Z”}}

When I try to create an asset with this:

curl -v -u apikey:apikey -H "Content-Type: application/json" -X POST -d '{ "name": "Test-01", "description":"Test Laptop", "asset_type_id": "13000142404" }' 'https://domain.freshservice.com/api/v2/assets'

It fails with:

{“description”:“Validation failed”,“errors”:[{“field”:“asset_type_id”,“message”:“It should be of type Integer”,“code”:“datatype_mismatch”}]}

I have tried other asset type ids as well and everything fails with the same error. What do I need to do to resolve this?

Hey, try to remove quotations from id and try.

curl -v -u apikey:apikey -H "Content-Type: application/json" -X POST -d '{ "name": "Test-01", "description":"Test Laptop", "asset_type_id": 13000142404 }' 'https://domain.freshservice.com/api/v2/assets'

1 Like

Yusra,

That looks to have gotten me further. I am now getting this error:

{“description”:“Validation failed”,“errors”:[{“field”:“product_13000142382”,“message”:“This field cannot be empty”,“code”:“missing_field”},{“field”:“asset_state_13000142382”,“message”:“This field cannot be empty”,“code”:“missing_field”}]

How can I give the fields product_13000142382 and asset_state_13000142382 with a new device? How am I supposed to know the id 13000142382?

Thanks,
Brian

Hello Brian,

This is the id of the asset type under which the asset type fields are created.