ArnesSI / netbox-inventory

Manage your hardware inventory in NetBox
MIT License
205 stars 21 forks source link

API : Look for assets by inventoryitem ID #178

Closed Eraseth closed 2 months ago

Eraseth commented 3 months ago

I want to retrieve the Asset associated with a specific Inventory Item. It looks like there is no filter for this case.

The followings request return all Assets and not the one associated with the inventory item with ID 50:

api/plugins/inventory/assets/?inventoryitem_id=42
api/plugins/inventory/assets/?inventoryitem=42
api/plugins/inventory/assets/?inventory_item=42
api/plugins/inventory/assets/?inventory_item_id=42

Any way to achieve this ?

matejv commented 2 months ago

I have added additional filters on assets endpoint. Now you can filter:

api/plugins/inventory/assets/?inventoryitem_id=42
api/plugins/inventory/assets/?inventoryitem=PSU1 # name of inventory item (exact, case insensitive)
api/plugins/inventory/assets/?module_id=33
api/plugins/inventory/assets/?device_id=22
api/plugins/inventory/assets/?device=my-router1 # name of device (exact, case insensitive)

Additionally you can repeat the same parameter so search on multiple values:

api/plugins/inventory/assets/?inventoryitem_id=42&inventoryitem_id=43

This will return assets where assigned inventory item ID is 42 OR 43.