Containers as Assets

Using DataTrails to Represent Containers

Represent Containers Using DataTrails

DataTrails Assets can be used to track the status, contents, location, and other key attributes of containers over time. This can also be done for containers within containers. For example, you may wish to track bags inside boxes that are inside a shipping container being transported on a train.

Create a Container Asset

A Container Asset is not a special type of asset, it is a label that is given to an Asset that has been created to represent a container. For more detail on the Asset creation process, please see our DataTrails Overview guide.
For this example, we will create a simple asset that we will call Shipping Container. Note that with DataTrails, we could also record more complex attributes such as size of the container, weight, location, or any other important details. For now, we will create a minimal Asset that includes the name and type.

Create the Shipping Container

Note: To use the YAML Runner you will need to install the datatrails-archivist python package.

Click here for installation instructions.

---
steps:
  - step:
      action: ASSETS_CREATE_IF_NOT_EXISTS
      description: Create a shipping container asset.
      asset_label: Shipping Container 
    selector: 
      - attributes: 
        - arc_display_name
    behaviours: 
      - RecordEvidence
    attributes: 
      arc_display_name: Shipping Container
      arc_display_type: Shipping Container
    confirm: true
cat > asset.json <<EOF
{
  "behaviours": ["RecordEvidence"],
  "attributes": {
      "arc_display_name": "Shipping Container",
      "arc_display_type": "Shipping Container"
  }
}
EOF

Use curl to POST the asset, viewing the result with jq:

curl -X POST \
     -H "@$HOME/.datatrails/bearer-token.txt" \
     -H "Content-Type: application/json" \
     -d "@asset.json" \
     https://app.datatrails.ai/archivist/v2/assets | jq

If errors occur, see Troubleshooting Token Generation

Associate an Item or Container with Another Container

Now that we have created a Shipping Container Asset, we can create another Asset to represent an item or a box of items that are to be shipped in the Shipping Container. To do this, we will create another Asset and add a custom Asset Attribute that links it to our Shipping Container. For example, let’s create an Asset to represent a box that is being transported within the Shipping Container.

Note: For this example, we used the custom attribute within_container, but you could use any key to associate the Assets that does not contain the reserved arc_ prefix.

  1. Set the Name and Type

    Create the Box
  2. Click Advanced Options

    Add an Extended Attribute
  3. Click ADD ATTRIBUTE to set Extended Attributes

  4. Add Attribute = within_container and Value = Shipping Container

  5. Click REGISTER ASSET to complete the association of the box within the container

  6. Repeat the above a few times, editing the Name to add several boxes within the Shipping Container

Note: To use the YAML Runner you will need to install the datatrails-archivist python package.

Click here for installation instructions.

---
steps:
  - step:
      action: ASSETS_CREATE_IF_NOT_EXISTS
      description: Create a box asset and associate with Shipping Container.
      asset_label: Box 
    selector: 
      - attributes: 
        - arc_display_name
    behaviours: 
      - RecordEvidence
    attributes: 
      arc_display_name: Box-1
      arc_display_type: Box
      within_container: Shipping Container
    confirm: true

Repeat the above a few times, editing the arc_display_name to add several boxes within the Shipping Container

cat > asset-box.json <<EOF
{
    "behaviours": ["RecordEvidence"],
    "attributes": {
        "arc_display_name": "Box-1",
        "arc_display_type": "Box",
        "within_container": "Shipping Container"
    }
}
EOF

Use curl to POST the asset, viewing the result with jq:

curl -X POST \
     -H "@$HOME/.datatrails/bearer-token.txt" \
     -H "Content-Type: application/json" \
     -d "@asset-box.json" \
     https://app.datatrails.ai/archivist/v2/assets | jq

Repeat the above a few times, editing the arc_display_name to add several boxes within the Shipping Container

If errors occur, see Troubleshooting Token Generation

The Box(es) have been recorded as being within the Shipping Container.

List All Assets Associated With a Container

To retrieve all Assets associated with a container, you can run a query with a filter that will identify which Assets have the attribute within_container set to the desired value. To list all Assets inside of Shipping Container:


  1. Select Audit/Filter in the navigation to filter Assets and Events within your tenancy

  2. Select ADD FILTER

  3. Select Asset Attribute, set the name to within_container and the value to Shipping Container

  4. Select APPLY FILTERS to view the subset of Assets created

    Filter Assets and Events

Note: To use the YAML Runner you will need to install the datatrails-archivist python package.

Click here for installation instructions.

---
steps:
  - step:
      action: ASSETS_LIST
      description: List all assets within Shipping Container.
      print_response: true
    attrs:
      within_container: Shipping Container
curl -g -X GET \
     -H "$HOME/.datatrails/bearer-token.txt" \
     "https://app.datatrails.ai/archivist/v2/assets?attributes.within_container=Shipping%20Container" | jq