{{sidenavigation.sidenavigationExpandLabel}}
{{getMsg('Help_YouAreHere')}}: {{page.title}} {{page.title}}
{{$root.getMsg("downLoadHelpAsPdf")}} {{helpModel.downloadHelpPdfDataStatus}}

Create

Using this handler, you can Create new assets. To create new assets, you simply send a list of properties and values for the asset to this handler.

POST /api/inventory/create

PUT /api/inventory/create

The handler supports the methods POST and PUT to send data. The request consists of asset field keys and values. There are some special fields you have to consider:

  • The asset type has to be set. It determines, which fields are allowed for this asset. The type is denoted by the number.
  • The asset field parent is the GUID of another asset to create a hierarchical structure for the assets. The parent field is optional.

The response object for an asset creation request is the same, as in an asset request.

Example Request

# Request
POST /api/inventory/create HTTP/1.1
Authorization: Bearer VGhpcyBpcyBqdXN0IGEgZGVtbyBhY2Nlc3MgdG9rZW4u
Content-Type: application/json
 
{
  "type": 26,
  "name": "Microsoft Office 365",
  "parent": "0xzpx5c1axxj8fa3t3r926kgd",
  "sla": 3,
  "room": "120",
  "license": 1,
  "purchasedate": 1700002800000,
  "price": 2037.3836663611166,
  "vendor": 1,
  "mycustomfield": "A custom value",
  "location": 56,
  "assetnumber": "DE-42-11",
  "costcenter": "General"
}
 
# Response
HTTP/1.1 200 OK
Content-Type: application/json
 
{
  "id": "7nu5btw9hxubqkc0baeca8fgp",
  "parent": "0xzpx5c1axxj8fa3t3r926kgd",
  "name": "Microsoft Office 365",
  "isArchived": false,
  "type": {
    "id": 26,
    "name": "Software"
  },
  "hasAttachments": false,
  "fields": {
    "owner": "26ljl61fdu8napr0sopu2ovqs",
    "license": 1,
    "purchasedate": 1700002800000,
    "price": 2037.3836663611166,
    "vendor": 1,
    "mycustomfield": "A custom value",
    "name": "Microsoft Office 365",
    "sla": 3,
    "location": 56,
    "assetnumber": "DE-42-11",
    "costcenter": "General",
    "room": "120"
  }
}

Application Example

# Browser access
http://127.0.0.1:9000/api/inventory/create
 
# Shell access using curl
curl -Ls "http://127.0.0.1:9000/api/inventory/create" \
     --header 'Authorization: Bearer VGhpcyBpcyBqdXN0IGEgZGVtbyBhY2Nlc3MgdG9rZW4u' \
     --header "Content-Type: application/json" \
     --request POST \
     --data '{"name": "Microsoft Office 365", "type": 26}'
 
# Shell access using curl with username and password
curl -Lsu username:password "http://127.0.0.1:9000/api/inventory/create" \
     --header "Content-Type: application/json" \
     --request POST \
     --data '{"name": "Microsoft Office 365", "type": 26}'

Updating Assets: POST /api/inventory/<asset-id>

As stated in the asset handler, you can update existing assets using the POST method on the /api/inventory/<asset-id> handler. To update an asset, send the asset fields you would like to change with their new values.

Note: to clear an asset field, you have to send an empty string value for the field key.

Adding Attachments

The request allows the upload of additional attachments. The following requirements have to be fulfilled for an attachment upload:

  • The request has to be performed using the Content-Type: multipart/form-data header
  • The JSON itself has to be sent as file attachment using the attribute name json
  • Attachment files have to have the attribute name attachment<X> with <X> being a number starting at 0; corresponding to the index of the attachment description list for the given attachment.
  • The JSON may contain a list of attachment descriptions (see below). The entry index has to match your attachment<X> - file. The list of attachment descriptions can be added to your JSON map using the attachments key.
REQUEST Fields Value Type Description
name string The file name of the attachment
lastModified long The timestamp of the last modification of this attachment (can be 0)

Note: The attachments field in the JSON is optional. However, if set, you can send the name and the lastModified date along. If the attachments field is omitted, the file name is derived from the file's multipart header.

Application Example

# Browser access
http://127.0.0.1:9000/api/inventory/create
http://127.0.0.1:9000/api/inventory/<asset-id>
 
# Shell access using curl
curl -Ls "http://127.0.0.1:9000/api/inventory/<asset-id>" \
     --header 'Authorization: Bearer VGhpcyBpcyBqdXN0IGEgZGVtbyBhY2Nlc3MgdG9rZW4u' \
     --header "Content-Type: multipart/form-data" \
     --request POST \
     --form 'json={}'
     --form attachment0="@first attachment.pdf"
     --form attachment1="@second attachment.pdf"
 
# Shell access using curl with username and password
curl -Lsu username:password "http://127.0.0.1:9000/api/inventory/<asset-id>" \
     --header "Content-Type: multipart/form-data" \
     --request POST \
     --form 'json={}'
     --form attachment0="@first attachment.pdf"
     --form attachment1="@second attachment.pdf"
 
# Note: The ''@'' sign is required for curl to recognize the input as a file.

Note: The example is valid for updating an asset. You can also send attachments along with an asset creation request. In that case, the JSON has to have at least the fields type and name.

To send a different attachment name and the lastModified field, please add the attachments field using the following JSON snippet.

{
  "attachments": [
    {
      "name": "first attachment.pdf",
      "lastModified": 0
    },
    {
      "name": "second attachment.pdf",
      "lastModified": 0
    }
  ]
}
i-net HelpDesk
This application uses cookies to allow login. By continuing to use this application, you agree to the use of cookies.


Help - /create