1. Assets
  2. Create Asset Serial Number Sequence

Assets

Create Asset Serial Number Sequence

POST
`/v1/asset/sequences`

Creating serial number sequences for assets requires two parameters; prefix, and sequence, a combination of which must be unique. By default the resource is set to asset.

js
        const data = {
  prefix: "PX-AST-",
  sequence: "QWASRT",
};

const res = await fetch(`https://api.packagex.io/v1/assets/sequences`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

const asset = res.data;

      

A sequence cannot be updated, however different serial number sequences for the same resource can share either the prefix or the sequence. For example, "PX-AST" prefix can have "ABCD" and "DEF" sequences. Likewise, "PX-ASSETT" can also have the "DEF" sequence. Likewise same serial number sequences can exist for different resources, however, a sequence created for a resource cannot be used for a different resource.

Creating a sequence with an existing prefix and sequence for the same resource will return the existing sequence with the message "Existing sequence returned".

Create & Update Asset

Create Asset

POST
`/v1/asset`

The only properties you need to create an asset is the item_id, location_id, and layout_id, which identify the item being converted to the asset and the location and layout where it will be placed. However, we recommend adding some more properties to the asset.

item_id string (required) the identifier of the item.
location_id string (required) the identifier of the location at which the asset will be created.
layout_id string the identifier of the layout at which the asset will be stored.
value string
The value of the asset
serial_number string
The serial number of the asset. If one is not provided, it will be autogenerated by the system.

| sequence_id string
This field is required if the asset serial number is to be assigned from an predefined sequence. Either ther serial_number or sequence_id should be passed | | currency string
The currency in which the value is defined, for example 'USD' | | barcode string
The barcode of the asset | | category string
Category of the asset, for example, Electronics | | sub_category string
The subcategory within the asset's category, for example, Smart Phone | | warranty_expires_at Date
The date at which the warranty expires | | is_warranty_valid string
A flag indicating whether the warranty is valid or not | | maintenance_schedule string
How often must the maintenance be performed on the asset. Can be daily, weekly, monthly, quarterly, or yearly | | options object
Options for asset, currently supports is_prefix flag, which determines whether the provided serial number is used as is, or if it is treated as a prefix for serial numbers. If set to true, sequence_id must not be null. Defaults to false | | next_maintenance_at Date
Next scheduled maintenance of the asset | | disposal_date string
When was the asset disposed off | | disposal_reason_code string
Reason code for asset disposal | | disposal_comment string
Additional comments for disposal | | purchased_at string
The date at which the asset was purchased | | initial_value string
The initial value of the asset before any appreciation or depreciation is applied | | maintenance_status string
The current maintenance status of the asset. Can be good, upcoming, required, ongoing | | manifest_id string
The subcategory within the asset's category, for example, Smart Phone | | linked_documents string
Any documents (like warranty_card, user_manual, invoice, transfer_order, POD, asset_request, other) associated to the asset |

js
        const data = {
  item_id: "item_5TngYZKdRFTSkcVCvNa885",
  layout_id: "lay_vgM65sMYtakxwfXkTCC8FB",
  location_id: "loc_8axWLqDo9kprqgNmFpCqxo",
  maintenance_schedule: "daily",
  maintenance_status: "good",
};

const res = await fetch(`https://api.packagex.io/v1/assets`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

const asset = res.data; //Refer to the asset model

      

To create an asset with a user defined serial number, pass the serial_number in the request body. However, if the serial number already exists in the database, the API will throw an error.

js
        const data = {
  item_id: "item_5TngYZKdRFTSkcVCvNa885",
  layout_id: "lay_vgM65sMYtakxwfXkTCC8FB",
  location_id: "loc_8axWLqDo9kprqgNmFpCqxo",
  serial_number: "PX-AST-1001"
  maintenance_schedule: "daily",
  maintenance_status: "good",
};

const res = await fetch(`https://api.packagex.io/v1/assets`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

const asset = res.data;

      

To use a predefined sequence for generating the asset serial number, pass the sequence_id instead

js
        const data = {
  item_id: "item_5TngYZKdRFTSkcVCvNa885",
  layout_id: "lay_vgM65sMYtakxwfXkTCC8FB",
  location_id: "loc_8axWLqDo9kprqgNmFpCqxo",
  sequence_id: "seq_dxEBJ9bS6gyZhxsmrrUMrM"
  maintenance_schedule: "daily",
  maintenance_status: "good",
};

const res = await fetch(`https://api.packagex.io/v1/assets`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

const asset = res.data; //Refer to the asset model

      

As sequences are finite length they may get exhausted. For example, if the user defines the sequence as 1 for a prefix PX-AST, the user will be able to create 9 assets before the sequence is exhausted. Likewise, if the user defines a sequence as 01, and another one as 10, the user will be able to create 10 assets for the first serial number before collisions start to occur.


Update Asset

POST
`/v1/assets/:asset_id`

Most of the asset properties can be updated, including

js
        metadata;
serial_number;
status;
maintenance_schedule;
maintenance_status;
value;
disposal_date;
disposal_reason_code;
disposal_comment;
purchased_at;
initial_value;
item_id;
location_id;
layout_id;
updated_at;
updated_by;

      

Likewise, linked documents can be added or removed as follows

js
        {
  linked_documents: {
    add: [
      {
        document_type: "warranty_card",
        image: "...", // base64 encoded image
      },
      {
        id: "ast_vgM65sMYtakxwfXkTCC8FB",
        document_type: "user_manual",
      },
    ];
    remove: [`doc_vgM65sMYtakxwfXkTCC8FB`];
  }
}

      

The objects containing id in add will be updated and the ones without the id will be created. The document ids pased in remove will be deleted. Overall, an update request may look as follows

js
        //Update lead time mins for a delivery and org's DBA name
const data = {
  maintenance_status: "upcoming",
  status: "in_use",
  linked_documents: {
    add: [
      {
        document_type: "warranty_card",
        image: "...", // base64 encoded image
      },
    ],
  },
};

const res = await fetch(`https://api.packagex.io/v1/assets/ast_1tH2ofoBcDbPnyZCYmrSX3`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

      

Bulk Serialize Asset Items

Assets can be bulk created and serialized against items that are marked as assets. For instance, if you have 10 asset items at a location A on a layout B, and you want to generate serial numbers for two of them and move them to layout C, the request will look like this

js
        //Update lead time mins for a delivery and org's DBA name
const data = {
  item_id: "item_5TngYZKdRFTSkcVCvNa885",
  source_layout_id: "lay_vgM65sMYtakxwfXkTCC8FB",
  location_id: "loc_8axWLqDo9kprqgNmFpCqxo",
  destination_layout_id: "lay_bnFvu9BvzfvZxvtuJk6vtQ",
  sequence_id: "seq_nieoNmFpCqadsdRF",
  qty: 2,
};

const res = await fetch(`https://api.packagex.io/v1/assets/serialize`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

      

sequence_id is required for bulk serialization. If the source and destination layouts are same, destination layout can be omitted from the body.

js
        //Update lead time mins for a delivery and org's DBA name
const data = {
  item_id: "item_5TngYZKdRFTSkcVCvNa885",
  source_layout_id: "lay_vgM65sMYtakxwfXkTCC8FB",
  location_id: "loc_8axWLqDo9kprqgNmFpCqxo",
  sequence_id: "seq_nieoNmFpCqadsdRF",
  qty: 2,
};

const res = await fetch(`https://api.packagex.io/v1/assets/serialize`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());

      

If the assets are being procured from external sources, and any existing item quantities are not to be turned into assets, source layout ID can be omitted. In this case, the user must pass an options object containing check_inventory set to false. Destination layout, however, is required in this case.

js
        //Update lead time mins for a delivery and org's DBA name
const data = {
    item_id: "item_5TngYZKdRFTSkcVCvNa885",
    destination_layout_id: "lay_bnFvu9BvzfvZxvtuJk6vtQ"
    location_id: "loc_8axWLqDo9kprqgNmFpCqxo",
    sequence_id: "seq_nieoNmFpCqadsdRF",
    qty: 2,
    options: {
      check_inventory: false
    }
  };

const res = await fetch(`https://api.packagex.io/v1/assets/serialize`, {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(data),
}).then((res) => res.json());