Reference: Gateway examples for Asset

Tanium Gateway provides a GraphQL API integration point for Tanium solutions, including Asset. Asset requests retrieve Asset products or endpoints based on Asset products, update Asset product tracking, and import assets to update or create assets.

For additional Gateway example syntax, see Reference: Filter syntax and Reference: Gateway examples.

Asset query filter syntax

Filter Asset queries when retrieving Asset products (query.assetProducts) or endpoints (query.assetProductEndpoints).

Asset product queries (assetProducts) support the following filter fields:

  • search

  • states

  • vendors

For more information on syntax, see assetProductsFilter in the Documentation Explorer pane of the query explorer.

Endpoint queries using assetProductEndpoints support the following filter fields:

  • name

  • vendor

  • version

  • usage

For more information on syntax, see assetProductEndpointsFilter in the Documentation Explorer pane of the query explorer.

Asset products

You can retrieve Asset products and filter based on product metadata. Define a filter object using the syntax:

JSON
filter {
  vendors: [
    "vendor-name-1",
    "vendor-name-2",
    "vendor-name-n..."
  ],
  search: "search-string",
  states: [Cataloged | Ignored | Tracked]
}

For example, the following request retrieves only Asset products with a vendor name of Example vendor, an Asset state of Cataloged, and the search string Product in either the vendor name or product name:

JSON
query exampleGetAssetProductsFiltered($first: Int, $vendor: String!, $search: String, $states: AssetProductState!) {
  assetProducts(
    first: $first, filter: {
      vendors: [$vendor],
      search: $search,
      states: [$states]
    }
  ) {
    edges {
      node {
        vendor
        name
        installation {
          installedCount
          usedCount
          unusedCount
          pendingUsage
        }
        usage {
          usageNotDetected
          notInstalled
          baselining
          limited
          normal
          high
        }
        tracking {
          state
          reportingPeriodDays
          normalMinutesUsedPerDay
          highMinutesUsedPerDay
          baselinePeriodDays
        }
        versions {
          version
          installs
        }
      }
    }
  }
}

Include the filter variables in the Variables panel:

JSON
{
  "first": 2,
  "vendor": "Example vendor",
  "search": "Product",
  "states": "Cataloged"
}

Endpoints based on Asset products

You can retrieve endpoints and filter the returned endpoints based on Asset product information. Define a filter object using the syntax:

JSON
filter {
  vendors: [
    "vendor-name-1",
    "vendor-name-2",
    "vendor-name-n..."
  ],
  name: "name-string",
  version: "version-string"
}

For example, the following request retrieves only endpoints that have installed the Example name product, with a vendor of Example vendor and version of 1.2.3:

JSON
query exampleGetEndpointsAssetProduct($first: Int, $vendor: String, $name: String, $version: String) {
  assetProductEndpoints(
    first: $first
    filter: {vendor: $vendor, name: $name, version: $version, usage: Normal}
  ) {
    edges {
      node {
        id
        eid
        computerName
        computerId
        serialNumber
        osPlatform
        operatingSystem
        servicePack
        manufacturer
        ipAddress
        userName
        createdAt
        updatedAt
      }
    }
  }
}

Include the filter variables in the Variables panel:

JSON
{
  "first": 2,
  "vendor": "Example vendor",
  "name": "Example name",
  "version": "1.2.3"
}

Get Asset products

query.assetProducts

The following query requires Asset and retrieves Asset products:

JSON
query exampleGetAssetProducts($first: Int) {
  assetProducts(
    first: $first
  ) {
    edges {
      node {
        vendor
        name
        installation {
          installedCount
          usedCount
          unusedCount
          pendingUsage
        }
        usage {
          usageNotDetected
          notInstalled
          baselining
          limited
          normal
          high
        }
        tracking {
          state
          reportingPeriodDays
          normalMinutesUsedPerDay
          highMinutesUsedPerDay
          baselinePeriodDays
        }
        versions {
          version
          installs
        }
      }
    }
  }
}

Include the cursor variable in the Variables panel or in your variables dictionary:

JSON
{
  "first": 2
}

Example response:

JSON
{
  "data": {
    "assetProducts": {
      "edges": [
        {
          "node": {
            "vendor": "Example vendor",
            "name": "Example product",
            "installation": {
              "installedCount": 8,
              "usedCount": 0,
              "unusedCount": 0,
              "pendingUsage": null
            },
            "usage": {
              "usageNotDetected": 0,
              "notInstalled": 0,
              "baselining": 0,
              "limited": 0,
              "normal": 0,
              "high": 0
            },
            "tracking": {
              "state": "Cataloged",
              "reportingPeriodDays": 90,
              "normalMinutesUsedPerDay": 60,
              "highMinutesUsedPerDay": 240,
              "baselinePeriodDays": 7
            },
            "versions": [
              {
                "version": "1.2.3",
                "installs": 2
              },
              {
                "version": "1.2.4",
                "installs": 2
              }
            ]
          }
        },
        {
          "node": {
            "vendor": "Example vendor 2",
            "name": "Example product 2",
            "installation": {
              "installedCount": 1,
              "usedCount": 0,
              "unusedCount": 0,
              "pendingUsage": null
            },
            "usage": {
              "usageNotDetected": 0,
              "notInstalled": 0,
              "baselining": 0,
              "limited": 0,
              "normal": 0,
              "high": 0
            },
            "tracking": {
              "state": "Cataloged",
              "reportingPeriodDays": 90,
              "normalMinutesUsedPerDay": 60,
              "highMinutesUsedPerDay": 240,
              "baselinePeriodDays": 7
            },
            "versions": [
              {
                "version": "0.1.2",
                "installs": 1
              }
            ]
          }
        }
      ]
    }
  }
}

The following query request filters and retrieves only Asset products with a vendor name of Example vendor, an Asset state of Cataloged, and the search string Product in either the vendor name or product name:

JSON
query exampleGetAssetProductsFiltered($first: Int, $vendor: String!, $search: String, $states: AssetProductState!) {
  assetProducts(
    first: $first, filter: {
      vendors: [$vendor],
      search: $search,
      states: [$states]
    }
  ) {
    edges {
      node {
        vendor
        name
        installation {
          installedCount
          usedCount
          unusedCount
          pendingUsage
        }
        usage {
          usageNotDetected
          notInstalled
          baselining
          limited
          normal
          high
        }
        tracking {
          state
          reportingPeriodDays
          normalMinutesUsedPerDay
          highMinutesUsedPerDay
          baselinePeriodDays
        }
        versions {
          version
          installs
        }
      }
    }
  }
}

Include the cursor and filter variables in the Variables panel or in your variables dictionary:

JSON
{
  "first": 2,
  "vendor": "Example vendor",
  "search": "Product",
  "states": "Cataloged"
}

Example response:

JSON
{
  "data": {
    "assetProducts": {
      "edges": [
        {
          "node": {
            "vendor": "Example vendor",
            "name": "Example product",
            "installation": {
              "installedCount": 8,
              "usedCount": 0,
              "unusedCount": 0,
              "pendingUsage": null
            },
            "usage": {
              "usageNotDetected": 0,
              "notInstalled": 0,
              "baselining": 0,
              "limited": 0,
              "normal": 0,
              "high": 0
            },
            "tracking": {
              "state": "Cataloged",
              "reportingPeriodDays": 90,
              "normalMinutesUsedPerDay": 60,
              "highMinutesUsedPerDay": 240,
              "baselinePeriodDays": 7
            },
            "versions": [
              {
                "version": "0.1.2",
                "installs": 2
              },
              {
                "version": "3.4.5",
                "installs": 2
              }
            ]
          }
        },
        {
          "node": {
            "vendor": "Example vendor",
            "name": "Product example",
            "installation": {
              "installedCount": 1,
              "usedCount": 0,
              "unusedCount": 0,
              "pendingUsage": null
            },
            "usage": {
              "usageNotDetected": 0,
              "notInstalled": 0,
              "baselining": 0,
              "limited": 0,
              "normal": 0,
              "high": 0
            },
            "tracking": {
              "state": "Cataloged",
              "reportingPeriodDays": 90,
              "normalMinutesUsedPerDay": 60,
              "highMinutesUsedPerDay": 240,
              "baselinePeriodDays": 7
            },
            "versions": [
              {
                "version": "6.7.8",
                "installs": 1
              }
            ]
          }
        }
      ]
    }
  }
}

Get endpoints based on Asset products

query.assetProductEndpoints

The following query requires Asset and retrieves the first 2 endpoints with the Example name product installed, associated with the Example vendor vendor and version 1.2.3:

JSON
query exampleGetEndpointsAssetProduct($first: Int, $vendor: String, $name: String, $version: String) {
  assetProductEndpoints(
    first: $first
    filter: {vendor: $vendor, name: $name, version: $version}
  ) {
    edges {
      node {
        id
        eid
        computerName
        computerId
        serialNumber
        osPlatform
        operatingSystem
        servicePack
        manufacturer
        ipAddress
        userName
        createdAt
        updatedAt
      }
    }
  }
}

Include the cursor and filtering variables in the Variables panel or in your variables dictionary:

JSON
{
  "first": 2,
  "vendor": "Example vendor",
  "name": "Example name",
  "version": "1.2.3"
}

Example response:

JSON
{
  "data": {
    "assetProductEndpoints": {
      "edges": [
        {
          "node": {
            "id": 123,
            "eid": 456789,
            "computerName": "example-host-1",
            "computerId": "123456789",
            "serialNumber": "1234567890abcdef",
            "osPlatform": "Windows",
            "operatingSystem": "Windows 10 Enterprise",
            "servicePack": "No Service Pack found",
            "manufacturer": "VMware, Inc.",
            "ipAddress": "192.0.2.10",
            "userName": "example-user",
            "createdAt": "2022-09-29T07:00:16.000Z",
            "updatedAt": "2022-11-10T23:00:06.000Z"
          }
        },
        {
          "node": {
            "id": 456,
            "eid": 789012,
            "computerName": "example-host-2",
            "computerId": "987654321",
            "serialNumber": "fedcba0987654321",
            "osPlatform": "Windows",
            "operatingSystem": "Windows 10 Enterprise",
            "servicePack": "No Service Pack found",
            "manufacturer": "VMware, Inc.",
            "ipAddress": "192.0.2.20",
            "userName": "example-user",
            "createdAt": "2022-09-29T07:00:16.000Z",
            "updatedAt": "2022-10-31T14:00:05.000Z"
          }
        }
      ]
    }
  }
}

Update Asset endpoints based on source

mutation.assetUpdateEndpoints

Stability: 1.2 - Experimental (Release Candidate)

The following mutation requires Asset and updates the endpoint record based on the default Tanium source. If reconciliation keys are included, asset reconciliation is used. If no endpoints match the keys, the response returns an error.

Note: To update an endpoint in the Tanium source, you must specify the Computer Name, Computer ID, and Endpoint Fingerprint keys. Asset finds the endpoint if at least two of the keys match.
Note: After you submit a successful request, it can take up to two import cycles, or approximately 20 minutes, for attributes to appear in Asset and in reports.
JSON
mutation exampleAssetUpdateEndpointsTaniumSource($input: AssetUpdateEndpointsInput!) {
  assetUpdateEndpoints(
    input: $input
  ) {
    assets {
      eid
      source {
        namespace
        id
        name
      }
      status
      error
    }
  }
}

Include the input variables in the Variables panel or in your variables dictionary:

JSON
{
  "input": {
    "sourceName": "Tanium",
    "entityNames": [
      "Computer Name",
      "Computer ID",
      "Endpoint Fingerprint",
      "Asset Custom: custom_entity_1"
    ],
    "assets": [
      {
        "entities": [
          {
            "entityName": "Computer Name",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Computer Name",
                    "value": "computer1"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Computer ID",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Computer ID",
                    "value": "1234567890"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Endpoint Fingerprint",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Endpoint Fingerprint",
                    "value": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Asset Custom: custom_entity_1",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Asset Custom: custom_entity_1",
                    "value": "example_value"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

Example response:

JSON
{
  "data": {
    "assetUpdateEndpoints": {
      "assets": [
        {
          "eid": "12345",
          "source": {
            "namespace": "Asset: Tanium",
            "id": "1",
            "name": "Tanium"
          },
          "status": "Updated",
          "error": null
        }
      ]
    }
  }
}

The following mutation updates the endpoint record based on a Microsoft Azure source:

Note: To update an endpoint in the Tanium source, you must specify the Computer Name, Computer ID, and Endpoint Fingerprint keys. Asset finds the endpoint if at least two of the keys match. For an example, see Update Asset endpoint by Asset source.
JSON
mutation exampleAssetUpdateEndpointsMicrosoftAzureSource($input: AssetUpdateEndpointsInput!) {
  assetUpdateEndpoints(
    input: $input
  ) {
    assets {
      eid
      source {
        namespace
        id
        name
      }
      status
      error
    }
  }
}

Include the input variables in the Variables panel or in your variables dictionary:

JSON
{
  "input": {
    "sourceName": "example Microsoft Azure source",
    "entityNames": [
      "Cloud Instance ID",
      "Asset Custom: custom_entity_1"
    ],
    "assets": [
      {
        "entities": [
          {
            "entityName": "Cloud Instance ID",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Cloud Instance ID",
                    "value": "12345678-90ab-cdef-1234-567890abcdef"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Asset Custom: custom_entity_1",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Asset Custom: custom_entity_1",
                    "value": "Test 1"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

Example response:

JSON
{
  "data": {
    "assetUpdateEndpoints": {
      "assets": [
        {
          "eid": "149157",
          "source": {
            "namespace": "Asset: example Microsoft Azure source",
            "id": "102",
            "name": "example Microsoft Azure source"
          },
          "status": "Updated",
          "error": null
        }
      ]
    }
  }
}

Update Asset endpoints based on endpoint ID (EID)

mutation.assetUpdateEndpointsUsingEid

Stability: 1.2 - Experimental (Release Candidate)

The following mutation requires Asset and updates the endpoint record for an Asset source that matches the endpoint ID (EID). If reconciliation keys are included, asset reconciliation is used. If no endpoints match the keys, the response returns an error.

Note: To update an endpoint in the Tanium source, you must specify the Computer Name, Computer ID, and Endpoint Fingerprint keys. Asset finds the endpoint if at least two of the keys match. For an example, see Update Asset endpoint by Asset source.
Note: After you submit a successful request, it can take up to two import cycles, or approximately 20 minutes, for attributes to appear in Asset and in reports.
JSON
mutation exampleAssetUpdateEndpointsEID($input: AssetUpdateEndpointsUsingEidInput!) {
  assetUpdateEndpointsUsingEid(input: $input) {
    assets {
      eid
      source {
        namespace
        id
        name
      }
      status
      error
    }
  }
}

Include the input variables in the Variables panel or in your variables dictionary:

JSON
{
  "input": {
    "sourceName": "example_source",
    "entityNames": [
      "Asset Custom: custom_entity_1"
    ],
    "assets": [
      {
        "eid": "12345",
        "entities": [
          {
            "entityName": "Asset Custom: custom_entity_1",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Asset Custom: custom_entity_1",
                    "value": "example_test"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

Example response:

JSON
{
  "data": {
    "assetUpdateEndpointsUsingEid": {
      "assets": [
        {
          "eid": "12345",
          "source": {
            "namespace": "Asset: example_source",
            "id": "123",
            "name": "example_source"
          },
          "status": "Updated",
          "error": null
        }
      ]
    }
  }
}

Upsert (create or update by ID) Asset endpoint

mutation.assetUpsertEndpoints

Stability: 1.2 - Experimental (Release Candidate)

The assetUpsertEndpoints mutation either creates a new endpoint record or updates an existing endpoint record using the defined sourceName for Import API sources. Asset creation or update is based on comparing key field values. If reconciliation keys are included, asset reconciliation is used. To determine whether an existing asset updates, or a new asset is created:

  1. If an imported asset key matches an existing asset key imported using the sourceName Import API source, that existing asset updates. The status in the response equals Updated.

  2. If an imported asset key matches an existing asset reconciliation key imported using the Tanium source only, that existing asset is reconciled, and then updates. The status in the response equals Reconciled.

  3. Otherwise, if no existing asset matches the imported asset, the asset is imported as a new asset using the sourceName Import API source. The status in the response is equal to Created.

Note: If the request is structurally and syntactically valid, each asset object imports separately. A failed asset import does not prevent other valid asset objects in that request from importing.
Note: After you submit a successful request, it can take up to two import cycles, or approximately 20 minutes, for attributes to appear in Asset and in reports.

The following mutation request creates an asset, if no existing asset in the example_source Import API source matches on the Computer Name key field, and updates a single attributeName value:

JSON
mutation exampleAssetUpsertEndpoints($input: AssetUpsertEndpointsInput!) {
  assetUpsertEndpoints(input: $input) {
    assets {
      eid
      source {
        namespace
        id
        name
      }
      status
      error
    }
  }
}

Include the variables in the Variables panel or in your variables dictionary:

JSON
{
  "input": {
    "sourceName": "example_source",
    "entityNames": [
      "Computer Name",
      "Asset Custom: custom_entity_1"
    ],
    "assets": [
      {
        "entities": [
          {
            "entityName": "Computer Name",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Computer Name",
                    "value": "computer1"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Asset Custom: custom_entity_1",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Asset Custom: custom_entity_1",
                    "value": "Test 1"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

As the request is evaluated, the asset object defines a value for the computerName key field, matching the key field defined for the example_source source, and is imported using that source. The example response shows a status of Created:

JSON
{
  "data": {
    "assetUpsertEndpoints": {
      "assets": [
        {
          "eid": "12345",
          "source": {
            "namespace": "Asset: example_source",
            "id": "123",
            "name": "example_source"
          },
          "status": "Created",
          "error": null
        }
      ]
    }
  }
}

The following mutation request updates an asset if an asset in the example_source Import API source matches on the Computer Name key field, and updates two attributeName values:

JSON
mutation exampleAssetUpsertEndpointsMultiColumn($input: AssetUpsertEndpointsInput!) {
  assetUpsertEndpoints(input: $input) {
    assets {
      eid
      source {
        namespace
        id
        name
      }
      status
      error
    }
  }
}

Include the variables in the Variables panel or in your variables dictionary:

JSON
{
  "input": {
    "sourceName": "example_source",
    "entityNames": [
      "Computer Name",
      "Asset Custom: custom_entity_2"
    ],
    "assets": [
      {
        "entities": [
          {
            "entityName": "Computer Name",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Computer Name",
                    "value": "computer1"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Asset Custom: custom_entity_2",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "column_1",
                    "value": "column_1_test"
                  },
                  {
                    "attributeName": "column_2",
                    "value": "column_2_test"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

As the request is evaluated, the asset object defines a value for the computerName key field, matching the key field defined for the example_source Import API source, and is imported using that source. The example response shows a status of Updated:

JSON
{
  "data": {
    "assetUpsertEndpoints": {
      "assets": [
        {
          "eid": "12345",
          "source": {
            "namespace": "Asset: example_source",
            "id": "123",
            "name": "example_source"
          },
          "status": "Updated",
          "error": null
        }
      ]
    }
  }
}

The following mutation request updates an asset if an asset in the example_source Import API source matches on the Computer Name key field, and updates two rows with two attributeName values:

JSON
mutation exampleAssetUpsertEndpointsMultiRow($input: AssetUpsertEndpointsInput!) {
  assetUpsertEndpoints(input: $input) {
    assets {
      eid
      source {
        namespace
        id
        name
      }
      status
      error
    }
  }
}

Include the variables in the Variables panel or in your variables dictionary:

JSON
{
  "input": {
    "sourceName": "ktai_example_custom_source",
    "entityNames": [
      "Computer Name",
      "Asset Custom: ktai_custom_entity_3"
    ],
    "assets": [
      {
        "entities": [
          {
            "entityName": "Computer Name",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "Computer Name",
                    "value": "computer1"
                  }
                ]
              }
            ]
          },
          {
            "entityName": "Asset Custom: ktai_custom_entity_3",
            "entityRowItems": [
              {
                "attributes": [
                  {
                    "attributeName": "multi_row_1",
                    "value": "row_1_column_1_test"
                  },
                  {
                    "attributeName": "multi_row_2",
                    "value": "row_1_column_2_test"
                  }
                ]
              },
              {
                "attributes": [
                  {
                    "attributeName": "multi_row_1",
                    "value": "row_2_column_1_test"
                  },
                  {
                    "attributeName": "multi_row_2",
                    "value": "row_2_column_2_test"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

As the request is evaluated, the asset object defines a value for the computerName key field, matching the key field defined for the example_source Import API source, and is imported using that source. The example response shows a status of Updated:

JSON
{
  "data": {
    "assetUpsertEndpoints": {
      "assets": [
        {
          "eid": "12345",
          "source": {
            "namespace": "Asset: example_source",
            "id": "123",
            "name": "example_source"
          },
          "status": "Updated",
          "error": null
        }
      ]
    }
  }
}

To verify the import, create a report based on the custom source definition, and filter the report to search for imported assets. For example, creating a report with Computer Name and Serial Number as columns, then filtering Computer Name for values containing computer and 23 returns the imported assets.

Figure 1. Example Asset import report
Example Asset import report
Note: You can also add the Asset source ID to view only assets from that source.

For more information, see Tanium Asset User Guide: Create a report.

Import assets

mutation.assetsImport

Stability: 0 - Deprecated

Note: This is deprecated in favor of mutation.assetUpsertEndpoints. For more information, see the example syntax.
Note: Before you submit this mutation request, you must configure an Asset custom source. For more information and an example workflow, see Create an Import API source.
Note: After you submit a successful request, it can take up to two import cycles, or approximately 20 minutes, for attributes to appear in Asset and in reports.

The assetsImport mutation imports assets defined in the request json variable value, using the defined sourceName custom source. To determine whether an existing asset updates, or a new asset is created:

  1. If an imported asset key matches an existing asset key imported using the sourceName custom source, that existing asset updates.

  2. If no existing asset from the configured source matches, but values in the imported asset match an existing asset key imported using a source different from the sourceName custom source, and the other source allows the sourceName custom source to update, the existing asset from the other source updates.

  3. Otherwise, if no existing asset matches the imported asset, the asset is imported as a new asset using the sourceName custom source.

Note: If the request is structurally and syntactically valid, each asset object imports separately. A failed asset import does not prevent other valid asset objects in that request from importing.

Define the json attribute as a JSON object array, with each object corresponding to an asset. Ensure that the Asset custom source passes the JSON object array according to the following guidelines:

  • Use the backslash escape character with each quotation mark (\") in the JSON array.

  • You must define key field values for each object. If you do not define the key field values, the object does not import and the response returns ErrorMissingKey status for that object.

  • You can define source field mappings to destination fields for each object. If you do not define a source field mapping, values from those source fields are imported as null values for that object.

  • Field values are defined per object; you cannot globally define a single field value in the request to apply to every imported asset object.

  • You can define up to 5000 asset objects per array, and by extension, per request.

The following example Asset custom source, named test-name, defines two field mappings for computer_name and serial_number and defines computer_name as a key field.

JSON
{
  "keys": [
    "computer_name"
  ],
  "fieldMaps": [
    {
      "destination": "computer_name",
      "source": "computerName"
    },
    {
      "destination": "serial_number",
      "source": "serialNumber"
    }
  ]
}

The following mutation request imports assets based on the variables definition:

JSON
mutation exampleImportAssets($source: String!, $json: String!) {
  assetsImport(input: {sourceName: $source, json: $json}) {
    assets {
      id
      index
      status
    }
  }
}

Include the variables in the Variables panel or in your variables dictionary.

The following variables manually define the test-name source for importing and two asset objects in the JSON object array. Each object has a value for the key field (computerName) and for the serialNumber field mapping.

JSON
{
  "source": "test-name",
  "json": "[{\"computerName\": \"computer123\", \"serialNumber\": \"testSerial123\"}, {\"computerName\": \"computer234\", \"serialNumber\": \"testSerial234\"}]"
}

As the request is evaluated, each asset object defines a value for the computerName key field, matching the key field defined for the test-name custom source, and both are imported using that source. The example response shows both objects with a status of Created:

JSON
{
  "data": {
    "assetsImport": {
      "assets": [
        {
          "id": 6,
          "index": 0,
          "status": "Created"
        },
        {
          "id": 7,
          "index": 1,
          "status": "Created"
        }
      ]
    }
  }
}

To verify the import, create a report based on the custom source definition, and filter the report to search for imported assets. For example, creating a report with Computer Name and Serial Number as columns, then filtering Computer Name for values containing computer and 23 returns the imported assets.

Figure 2. Example Asset import report
Example Asset import report

For more information, see Create a report.