unable to set primary_mac_address with api #10968

Closed
opened 2025-12-29 21:38:33 +01:00 by adam · 3 comments
Owner

Originally created by @lka on GitHub (Mar 31, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.2.6

Python Version

3.11

Steps to Reproduce

  1. Device with Interface and MAC address created
  2. use api or postman to assign primary_mac_address to interface
    PATCH http://netbox/api/dcim/interfaces/89/
    with data:
{
    "pimary_mac_address": {
        "id": 11
    }
}

or

curl -X 'PATCH' \
  'http://homeassistant:5580/api/dcim/interfaces/89/' \
  -H 'accept: application/json' \
  -H 'Authorization: $TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'X-CSRFTOKEN: $OTHER_TOKEN' \
  -d '{
  "pimary_mac_address": {"id": "11"}
}'

Expected Behavior

returns STATUS_CODE 200
and primary_mac_address is assigned

Observed Behavior

returning status_code 200
but:

...
"mac_address": null,
    "primary_mac_address": null,
    "mac_addresses": [
        {
            "id": 11,
            "url": "http://netbox/api/dcim/mac-addresses/11/",
            "display": "50:8B:B9:62:95:F4",
            "mac_address": "50:8B:B9:62:95:F4",
            "description": ""
        }
    ],
...
Originally created by @lka on GitHub (Mar 31, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.2.6 ### Python Version 3.11 ### Steps to Reproduce 1. Device with Interface and MAC address created 2. use api or postman to assign primary_mac_address to interface `PATCH http://netbox/api/dcim/interfaces/89/` with data: ``` { "pimary_mac_address": { "id": 11 } } ``` or ``` curl -X 'PATCH' \ 'http://homeassistant:5580/api/dcim/interfaces/89/' \ -H 'accept: application/json' \ -H 'Authorization: $TOKEN' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: $OTHER_TOKEN' \ -d '{ "pimary_mac_address": {"id": "11"} }' ``` ### Expected Behavior returns STATUS_CODE 200 and primary_mac_address is assigned ### Observed Behavior returning status_code 200 but: ``` ... "mac_address": null, "primary_mac_address": null, "mac_addresses": [ { "id": 11, "url": "http://netbox/api/dcim/mac-addresses/11/", "display": "50:8B:B9:62:95:F4", "mac_address": "50:8B:B9:62:95:F4", "description": "" } ], ... ```
adam added the netbox label 2025-12-29 21:38:33 +01:00
adam closed this issue 2025-12-29 21:38:33 +01:00
Author
Owner

@jnovinger commented on GitHub (Apr 2, 2025):

Possibly related to #18821 .

Going to accept this as undesired behavior at the very least, since the API is returning a 200 as if everything was successful (and in fact the dev server output indicates something happened, which actually did not).

The fix for this issue is to return a validation error, as this appears to have been somewhat expected in the work for #4867 . I think anything beyond that needs to be a separate Feature Request or covered by #18821.

@jnovinger commented on GitHub (Apr 2, 2025): Possibly related to #18821 . Going to accept this as undesired behavior at the very least, since the API is returning a 200 as if everything was successful (and in fact the dev server output indicates something happened, which actually did not). The fix for this issue is to return a validation error, as this appears to have been somewhat expected in the work for #4867 . I think anything beyond that needs to be a separate [Feature Request](https://github.com/netbox-community/netbox/issues/new?template=01-feature_request.yaml) or covered by #18821.
Author
Owner

@jeremystretch commented on GitHub (Apr 28, 2025):

I'm not able to reproduce this on NetBox v4.2.8. @lka could you please update and try again?

$ curl -X PATCH \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/dcim/interfaces/1623/ \
--data '{"primary_mac_address": {"id": 1}}'
{
    "id": 1623,
    "url": "http://netbox:8000/api/dcim/interfaces/1623/",
    "display_url": "http://netbox:8000/dcim/interfaces/1623/",
    "display": "ge-0/0/0",
    "device": {
        "id": 107,
        "url": "http://netbox:8000/api/dcim/devices/107/",
        "display": "device1",
        "name": "device1",
        "description": ""
    },
    "vdcs": [],
    "module": null,
    "name": "ge-0/0/0",
    "label": "",
    "type": {
        "value": "1000base-t",
        "label": "1000BASE-T (1GE)"
    },
    "enabled": true,
    "parent": null,
    "bridge": null,
    "lag": null,
    "mtu": null,
    "mac_address": "00:00:00:00:00:0A",
    "primary_mac_address": {
        "id": 1,
        "url": "http://netbox:8000/api/dcim/mac-addresses/1/",
        "display": "00:00:00:00:00:0A",
        "mac_address": "00:00:00:00:00:0A",
        "description": ""
    },
    "mac_addresses": [
        {
            "id": 1,
            "url": "http://netbox:8000/api/dcim/mac-addresses/1/",
            "display": "00:00:00:00:00:0A",
            "mac_address": "00:00:00:00:00:0A",
            "description": ""
        }
    ],
    "speed": null,
    "duplex": null,
    "wwn": null,
    "mgmt_only": false,
    "description": "",
    "mode": null,
    "rf_role": null,
    "rf_channel": null,
    "poe_mode": null,
    "poe_type": null,
    "rf_channel_frequency": null,
    "rf_channel_width": null,
    "tx_power": null,
    "untagged_vlan": null,
    "tagged_vlans": [],
    "qinq_svlan": null,
    "vlan_translation_policy": null,
    "mark_connected": false,
    "cable": null,
    "cable_end": null,
    "wireless_link": null,
    "link_peers": [],
    "link_peers_type": null,
    "wireless_lans": [],
    "vrf": null,
    "l2vpn_termination": null,
    "connected_endpoints": null,
    "connected_endpoints_type": null,
    "connected_endpoints_reachable": null,
    "tags": [],
    "custom_fields": {},
    "created": "2025-04-28T14:39:51.818157Z",
    "last_updated": "2025-04-28T14:42:38.868495Z",
    "count_ipaddresses": 0,
    "count_fhrp_groups": 0,
    "_occupied": false
}
@jeremystretch commented on GitHub (Apr 28, 2025): I'm not able to reproduce this on NetBox v4.2.8. @lka could you please update and try again? ``` $ curl -X PATCH \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/dcim/interfaces/1623/ \ --data '{"primary_mac_address": {"id": 1}}' { "id": 1623, "url": "http://netbox:8000/api/dcim/interfaces/1623/", "display_url": "http://netbox:8000/dcim/interfaces/1623/", "display": "ge-0/0/0", "device": { "id": 107, "url": "http://netbox:8000/api/dcim/devices/107/", "display": "device1", "name": "device1", "description": "" }, "vdcs": [], "module": null, "name": "ge-0/0/0", "label": "", "type": { "value": "1000base-t", "label": "1000BASE-T (1GE)" }, "enabled": true, "parent": null, "bridge": null, "lag": null, "mtu": null, "mac_address": "00:00:00:00:00:0A", "primary_mac_address": { "id": 1, "url": "http://netbox:8000/api/dcim/mac-addresses/1/", "display": "00:00:00:00:00:0A", "mac_address": "00:00:00:00:00:0A", "description": "" }, "mac_addresses": [ { "id": 1, "url": "http://netbox:8000/api/dcim/mac-addresses/1/", "display": "00:00:00:00:00:0A", "mac_address": "00:00:00:00:00:0A", "description": "" } ], "speed": null, "duplex": null, "wwn": null, "mgmt_only": false, "description": "", "mode": null, "rf_role": null, "rf_channel": null, "poe_mode": null, "poe_type": null, "rf_channel_frequency": null, "rf_channel_width": null, "tx_power": null, "untagged_vlan": null, "tagged_vlans": [], "qinq_svlan": null, "vlan_translation_policy": null, "mark_connected": false, "cable": null, "cable_end": null, "wireless_link": null, "link_peers": [], "link_peers_type": null, "wireless_lans": [], "vrf": null, "l2vpn_termination": null, "connected_endpoints": null, "connected_endpoints_type": null, "connected_endpoints_reachable": null, "tags": [], "custom_fields": {}, "created": "2025-04-28T14:39:51.818157Z", "last_updated": "2025-04-28T14:42:38.868495Z", "count_ipaddresses": 0, "count_fhrp_groups": 0, "_occupied": false } ```
Author
Owner

@lka commented on GitHub (Apr 28, 2025):

Hi Jeremy,

I found the error, it was my fault. I wrote "pimary_mac_address" instead of "primary_mac_address".
But the behaviour is strange. The answer code is 200 although the keyword "pimary_mac_address" can't be found.

Sorry for that.

PS: I have v4.2.8

@lka commented on GitHub (Apr 28, 2025): Hi Jeremy, I found the error, it was my fault. I wrote "pimary_mac_address" instead of "primary_mac_address". But the behaviour is strange. The answer code is 200 although the keyword "pimary_mac_address" can't be found. Sorry for that. PS: I have v4.2.8
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10968