Add 'interface_connection.id' to output of '/api/dcim/interfaces/[id]/' #1677

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

Originally created by @bdlamprecht on GitHub (Apr 17, 2018).

Issue type

[X] Feature request

Environment

  • Python version: 3.5.2
  • NetBox version: 2.3.2

Description

Currently, when you hit the API at /api/dcim/interfaces/[id]/ you get a lot of attributes such device, is_connected, description, and more importantly, interface_connection. All of this is very helpful, but what is missing that I'd like to have added is the id of the interface_connection (if applicable).

For example, the output you get from /api/dcim/interfaces/59/ is as follows (some fields have been removed for brevity):

{
    "id": 59,
    "device": {
        "id": 135,
        "url": "/api/dcim/devices/135/",
        "name": "foo-bar-b",
        "display_name": "foo-bar-b"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "is_connected": true,
    "interface_connection": {
        "interface": {
            "id": 56,
            "url": "/api/dcim/interfaces/56/",
            "device": {
                "id": 134,
                "url": "/api/dcim/devices/134/",
                "name": "foo-bar-a",
                "display_name": "foo-bar-a"
            },
            "name": "xe-0/0/0",
            "enabled": true,
            "description": ""
        },
        "status": true
    }
}

I know I can get the information I'm looking for (i.e. the id for the interface_connection) by hitting the API at /api/dcim/interface_connections/?device=foo-bar-a and doing some basic logic to determine if the device in question is on the "a-side" or the "b-side" of the interface_connection.

For example, you get the following output (some fields have also been remove for brevity):

{
    "count": 4,
    "results": [
        {
            "id": 2,
            "interface_a": {
                "id": 59,
                "url": "/api/dcim/interfaces/59/",
                "device": {
                    "id": 135,
                    "url": "/api/dcim/devices/135/",
                    "name": "foo-bar-b",
                    "display_name": "foo-bar-b"
                },
                "name": "xe-0/0/0",
                "form_factor": {
                    "value": 1200,
                    "label": "SFP+ (10GE)"
                },
                "enabled": true,
                "lag": null,
                "mtu": null,
                "mac_address": null,
                "mgmt_only": false,
                "description": ""
            },
            "interface_b": {
                "id": 56,
                "url": "/api/dcim/interfaces/56/",
                "device": {
                    "id": 134,
                    "url": "/api/dcim/devices/134/",
                    "name": "foo-bar-a",
                    "display_name": "foo-bar-a"
                },
                "name": "xe-0/0/0",
                "form_factor": {
                    "value": 1200,
                    "label": "SFP+ (10GE)"
                },
                "enabled": true,
                "lag": null,
                "mtu": null,
                "mac_address": null,
                "mgmt_only": false,
                "description": ""
            },
            "connection_status": {
                "value": true,
                "label": "Connected"
            }
        }
    ]
}

In summary, the desired output I'd like to get of /api/dcim/interfaces/59/ is the following (note the added id of interface_connection):

{
    "id": 59,
    "device": {
        "id": 135,
        "url": "/api/dcim/devices/135/",
        "name": "foo-bar-b",
        "display_name": "foo-bar-b"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "is_connected": true,
    "interface_connection": {
        "id": 2,
        "interface": {
            "id": 56,
            "url": "/api/dcim/interfaces/56/",
            "device": {
                "id": 134,
                "url": "/api/dcim/devices/134/",
                "name": "foo-bar-a",
                "display_name": "foo-bar-a"
            },
            "name": "xe-0/0/0",
            "enabled": true,
            "description": ""
        },
        "status": true
    }
}

I don't imagine that this would take too much effort to implement (perhaps one to two lines of code), but if that is not the base, please let me know and I'll go back the "hack" that I was using previously.

Originally created by @bdlamprecht on GitHub (Apr 17, 2018). ### Issue type [X] Feature request ### Environment * Python version: 3.5.2 * NetBox version: 2.3.2 ### Description Currently, when you hit the API at `/api/dcim/interfaces/[id]/` you get a lot of attributes such `device`, `is_connected`, `description`, and more importantly, `interface_connection`. All of this is very helpful, but what is missing that I'd like to have added is the `id` of the `interface_connection` (if applicable). For example, the output you get from `/api/dcim/interfaces/59/` is as follows (some fields have been removed for brevity): ``` { "id": 59, "device": { "id": 135, "url": "/api/dcim/devices/135/", "name": "foo-bar-b", "display_name": "foo-bar-b" }, "enabled": true, "lag": null, "mtu": null, "mac_address": null, "mgmt_only": false, "description": "", "is_connected": true, "interface_connection": { "interface": { "id": 56, "url": "/api/dcim/interfaces/56/", "device": { "id": 134, "url": "/api/dcim/devices/134/", "name": "foo-bar-a", "display_name": "foo-bar-a" }, "name": "xe-0/0/0", "enabled": true, "description": "" }, "status": true } } ``` I know I can get the information I'm looking for (i.e. the `id` for the `interface_connection`) by hitting the API at `/api/dcim/interface_connections/?device=foo-bar-a` and doing some basic logic to determine if the `device` in question is on the "a-side" or the "b-side" of the `interface_connection`. For example, you get the following output (some fields have also been remove for brevity): ``` { "count": 4, "results": [ { ``` ``` "id": 2, ``` ``` "interface_a": { "id": 59, "url": "/api/dcim/interfaces/59/", "device": { "id": 135, "url": "/api/dcim/devices/135/", "name": "foo-bar-b", "display_name": "foo-bar-b" }, "name": "xe-0/0/0", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": null, "mtu": null, "mac_address": null, "mgmt_only": false, "description": "" }, "interface_b": { "id": 56, "url": "/api/dcim/interfaces/56/", "device": { "id": 134, "url": "/api/dcim/devices/134/", "name": "foo-bar-a", "display_name": "foo-bar-a" }, "name": "xe-0/0/0", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": null, "mtu": null, "mac_address": null, "mgmt_only": false, "description": "" }, "connection_status": { "value": true, "label": "Connected" } } ] } ``` In summary, the **desired** output I'd like to get of `/api/dcim/interfaces/59/` is the following (note the added `id` of `interface_connection`): ``` { "id": 59, "device": { "id": 135, "url": "/api/dcim/devices/135/", "name": "foo-bar-b", "display_name": "foo-bar-b" }, "enabled": true, "lag": null, "mtu": null, "mac_address": null, "mgmt_only": false, "description": "", "is_connected": true, "interface_connection": { ``` ``` "id": 2, ``` ``` "interface": { "id": 56, "url": "/api/dcim/interfaces/56/", "device": { "id": 134, "url": "/api/dcim/devices/134/", "name": "foo-bar-a", "display_name": "foo-bar-a" }, "name": "xe-0/0/0", "enabled": true, "description": "" }, "status": true } } ``` I don't imagine that this would take too much effort to implement (perhaps one to two lines of code), but if that is not the base, please let me know and I'll go back the "hack" that I was using previously.
adam added the status: accepted label 2025-12-29 16:34:20 +01:00
adam closed this issue 2025-12-29 16:34:20 +01:00
Author
Owner

@bdlamprecht commented on GitHub (Apr 17, 2018):

One thing that I forgot to mention is why does /api/dcim/interfaces/ allow for the filters ?device=[NAME] AND ?device_id=[ID] but /api/dcim/interface-connections/ only allows for ?device=[NAME]?

Not a huge issue, but I'd imagine that consistency between the two would be fairly important.

@bdlamprecht commented on GitHub (Apr 17, 2018): One thing that I forgot to mention is why does `/api/dcim/interfaces/` allow for the filters `?device=[NAME]` **AND** `?device_id=[ID]` but `/api/dcim/interface-connections/` only allows for `?device=[NAME]`? Not a huge issue, but I'd imagine that consistency between the two would be fairly important.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1677