Already a NinjaOne customer? Log in to view more guides and the latest updates.

Accessing Core Asset Fields with API Scripts

Topic

This article explains how to update specific asset fields using the Command Line Interface (CLI) and NinjaOne's Application Programming Interface (API). 

Environment

  • NinjaOne IT Asset Management (ITAM)
  • NinjaOne Public API
  • NinjaOne Endpoint Management

Description

You can interact with core asset fields via the API using the custom field endpoints and their internal names. Additionally, you can use NinjaOne CLI to fetch and update the Asset ID and Asset Serial Number. 

Select a category to learn more: 

Update Core Asset Fields With CLI

To interact with core asset fields via the CLI, you must use the following internal field names: 

Asset Field NameInternal Field Name
Asset IDitamAssetID
Asset Serial Number itamAssetSerialNumber

The following code block provides an example of how you can interact with the fields: 

ninja-Property-get itamAssetID
ExampleAsset-001

ninja-Property-get itamAssetSerialNumber
1234567890

ninja-Property-set itamAssetID UpdatedAssetID

ninja-Property-set itamAssetSerialNumber UpdatedSerialNumber

Update Core Asset Fields With API

You can use NinjaOne's public API to interact with core asset fields by using the custom field endpoints and their internal names: 

Asset Field NameInternal Field Name
Asset IDitamAssetId
Asset statusitamAssetStatus
Purchase DateitamAssetPurchaseDate
Purchase AmountitamAssetPurchaseAmount
Expected LifetimeitamAssetExpectedLifetime
End of life dateitamAssetEndOfLifeDate
Asset serial numberitamAssetSerialNumber

Fetch Field Values

The following command code block provides an example of how you can fetch field values: 

$Fields = (Invoke-WebRequest -uri "$($NinjaURL)/v2/device/21/custom-fields" -Method Get -Headers $AuthHeader -ContentType 'application/json').Content | ConvertFrom-Json
$Fields | Select itamAssetId, itamAssetStatus, itamAssetPurchaseDate, itamAssetPurchaseAmount, itamAssetExpectedLifetime, itamAssetEndOfLifeDate, itamAssetSerialNumber

itamAssetId               : UpdateAssetID
itamAssetStatus           : In use
itamAssetPurchaseDate     : 1759316400000
itamAssetPurchaseAmount   : 1000
itamAssetExpectedLifetime : 2 years
itamAssetEndOfLifeDate    : 1822388400000
itamAssetSerialNumber     : UpdateSerialNumber

Set Field Values

Date fields require a UTC timestamp in milliseconds. The expected lifetime must be entered using lowercase letters.

The following command code block provides an example of how you can set field values: 

$AssetFields = @{
    itamAssetId = 'UpdatedViaAPIID'
    itamAssetStatus = 'Provisioning'
    itamAssetPurchaseDate = 1759316400000
    itamAssetPurchaseAmount = '1500'
    itamAssetExpectedLifetime = '3 years'
    itamAssetEndOfLifeDate = 1822388400000
    itamAssetSerialNumber = 'UpdatedViaAPISerial'
} | ConvertTo-Json

$Fields = (Invoke-WebRequest -uri "$($NinjaURL)/v2/device/21/custom-fields" -Method PATCH -Headers $AuthHeader -Body $AssetFields -ContentType 'application/json').Content | ConvertFrom-Json

Additional Resources

Refer to the following resources to learn more about asset management in NinjaOne:

FAQ

Next Steps