Expose 'Related Devices' pane present in the WebUI to the API #1281

Closed
opened 2025-12-29 16:31:02 +01:00 by adam · 1 comment
Owner

Originally created by @bdlamprecht on GitHub (Oct 5, 2017).

Issue type

[X] Feature request

Environment

  • NetBox version: v2.1.5

Description

Currently, when looking in the WebUI for a individual device, there is a pane listing Related Devices. I'd like to know what would be required to make that list available via the RestAPI.

What I'm trying to do (that this feature would allow me to) is to easily automate the configuration for pairs of devices, such as Core-A would be paired with Core-B (such as when I query the API for the A device, I would be able to know what its "partner" device is (via id).

Originally created by @bdlamprecht on GitHub (Oct 5, 2017). ### Issue type [X] Feature request <!-- Requesting the implementation of a new feature --> ### Environment * NetBox version: v2.1.5 ### Description Currently, when looking in the WebUI for a individual `device`, there is a pane listing **Related Devices**. I'd like to know what would be required to make that `list` available via the RestAPI. What I'm trying to do (that this feature would allow me to) is to _easily_ automate the configuration for pairs of devices, such as `Core-A` would be paired with `Core-B` (such as when I query the API for the `A` device, I would be able to know what its "partner" device is (via `id`).
adam closed this issue 2025-12-29 16:31:03 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 6, 2017):

The list of related devices is purely a UI function. It's provided on the page as a convenience. The query for it is:

# Find up to ten devices in the same site with the same functional role for quick reference.
related_devices = Device.objects.filter(
    site=device.site, device_role=device.device_role
).exclude(
    pk=device.pk
).select_related(
    'rack', 'device_type__manufacturer'
)[:10]

To roughly replicate this with an API request:

GET /api/dcim/devices/?site={{site}}&device_role={{device_role}}&limit=10

The only odd bit would be excluding the device in question. You could just do limit=11 and pop the device if it appears in the results (or pop the eleventh device).

@jeremystretch commented on GitHub (Oct 6, 2017): The list of related devices is purely a UI function. It's provided on the page as a convenience. The query for it is: ``` # Find up to ten devices in the same site with the same functional role for quick reference. related_devices = Device.objects.filter( site=device.site, device_role=device.device_role ).exclude( pk=device.pk ).select_related( 'rack', 'device_type__manufacturer' )[:10] ``` To roughly replicate this with an API request: ``` GET /api/dcim/devices/?site={{site}}&device_role={{device_role}}&limit=10 ``` The only odd bit would be excluding the device in question. You could just do `limit=11` and pop the device if it appears in the results (or pop the eleventh device).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1281