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.

I have the same problem. Did you find a resolution?

Having the same problem without a solution… anyone got an idea?

Hi All,

You are trying to create asset with

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'

which is fine as per the info we found in the documentation. Which is while creating assets “Name, Description, asset type” these fields are mandatory and required.
But when you choose asset type id “13000142404” this must be some asset type id like “for laptop” or might be anything else right?

So, point is when you provide the asset type id (let say in your case its “Laptop”), their is another filed which becomes mandatory and you need to provide the value for that as well.

While choosing Laptop as a asset type Two more fields are now mandatory (Product, Asset State) which you need to provide values for.

see the attached screenshots for reference and better understanding of the fields im talking about.

Hope this helps!!

@Haim_Ziv
@yusrakhatri

Cheers,
Umar