Creating an asset Via API - failed

Hi!
I am trying to create a new Asset using this method (POST):
https://fiverr.freshservice.com/api/v2/assets

This is the body request:

{'name': 'MONITOR Color LCD', 'description': 'INFO: 2017\nSN: NULL\nWIFI: Partner_C97787_5)Date: 2022-03-09 19:48:16', 'user_id': 110023536373, 'asset_type_id': 110030801420}

According to the API Doc, it includes all the needed fields ( Service Desk API for Developers | Freshservice)

However, once posted it failed with the following errors:

Validation failed
[{'field': 'product_11000801411', 'message': 'This field cannot be empty', 'code': 'missing_field'}, {'field': 'asset_state_11000801411', 'message': 'This field cannot be empty', 'code': 'missing_field'}]

These fields are not mentioned in the API Document.

Any idea how to solve it?

Hi Haim Ziv

Welcome to the freshworks developer community!

I haven’t used the assets API much but on playing around to solve this I have a few suggestions

  • Apart from the mandatory fields that are given for the create asset API you might also have to send the mandatory fields needed for that particular asset type

  • To get the list of mandatory asset type fields for your asset type try this

      `https://{{domain}}.freshservice.com/api/v2/asset_types/[asset_type_id]/fields`
    

    Sample response

      {
          "asset_type_fields": [
              {
                  "field_header": "test",
                  "fields": [
                      {
                          "id": 1073433815,
                          "created_at": "2022-03-13T16:06:30Z",
                          "updated_at": "2022-03-13T16:06:30Z",
                          "asset_type_id": 1024908431,
                          "name": "testing_required_1024908431",
                          "label": "testing_required",
                          "required": true,
                          "is_unique": false,
                          "field_type": "text",
                          "data_type": "string",
                          "default_field": false
                      }
                  ]
              }
          ]
      }
    

    In the response look for your asset type’s name in the “field_header” key and check the fields listed for it ( specifically the required attribute for each field ) and make sure that you are passing the values for all the required fields while creating an asset of this type.

    Note - Mostly the name of all the fields would be the name that you gave while creating the field_<asset_type_id>

Hope this helps you out, if not please let us know :slightly_smiling_face:

1 Like