Deprecate the _choices API endpoints #2797

Closed
opened 2025-12-29 18:22:16 +01:00 by adam · 9 comments
Owner

Originally created by @jeremystretch on GitHub (Aug 9, 2019).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.5.2
  • NetBox version: 2.6.2

Proposed Change

The NetBox REST API provides a _choices endpoint under each app (e.g. /api/circuits/_choices/) which lists the available values and labels for each choice field within the app. As @lampwins recently pointed out, the Django REST Framework exposes these choices (as well as other useful field attributes) via an OPTIONS HTTP request.

More investigation is needed, however it is likely that we can ditch the statically defined _choices endpoints in favor of using the built-in OPTIONS behavior.

Originally created by @jeremystretch on GitHub (Aug 9, 2019). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.5.2 * NetBox version: 2.6.2 ### Proposed Change The NetBox REST API provides a `_choices` endpoint under each app (e.g. `/api/circuits/_choices/`) which lists the available values and labels for each choice field within the app. As @lampwins recently pointed out, the Django REST Framework exposes these choices (as well as other useful field attributes) via an `OPTIONS` HTTP request. More investigation is needed, however it is likely that we can ditch the statically defined `_choices` endpoints in favor of using the built-in `OPTIONS` behavior.
adam added the status: acceptedtype: deprecation labels 2025-12-29 18:22:16 +01:00
adam closed this issue 2025-12-29 18:22:16 +01:00
Author
Owner

@lampwins commented on GitHub (Aug 10, 2019):

Also of note, the OPTIONS method uses the keys display_name and value, so we should look at deprecating the use of label in the ChoiceField, used for Swagger introspection. This is also more in line with Django naming convention anyway.

@lampwins commented on GitHub (Aug 10, 2019): Also of note, the OPTIONS method uses the keys `display_name` and `value`, so we should look at deprecating the use of `label` in the ChoiceField, used for Swagger introspection. This is also more in line with Django naming convention anyway.
Author
Owner

@tyler-8 commented on GitHub (Aug 20, 2019):

pynetbox needs to be updated to use the OPTIONS retrieval in step with the deprecation. Perhaps that should happen sooner so that by the time the _choices API is removed, pynetbox users will be none-the-wiser.

@tyler-8 commented on GitHub (Aug 20, 2019): `pynetbox` needs to be updated to use the `OPTIONS` retrieval in step with the deprecation. Perhaps that should happen sooner so that by the time the `_choices` API is removed, `pynetbox` users will be none-the-wiser.
Author
Owner

@markkuleinio commented on GitHub (Oct 18, 2019):

Is there a minimum NetBox version where this OPTIONS interface is available?

I sent a PR in pynetbox to implement the OPTIONS request, but if there is some version dependency then it needs to be mentioned in pynetbox documentation.

@markkuleinio commented on GitHub (Oct 18, 2019): Is there a minimum NetBox version where this `OPTIONS` interface is available? I sent a PR in pynetbox to implement the `OPTIONS` request, but if there is some version dependency then it needs to be mentioned in pynetbox documentation.
Author
Owner

@lampwins commented on GitHub (Oct 18, 2019):

@markkuleinio no, this is a feature of DRF and has always been available in netbox.

@lampwins commented on GitHub (Oct 18, 2019): @markkuleinio no, this is a feature of DRF and has always been available in netbox.
Author
Owner

@markkuleinio commented on GitHub (Nov 12, 2019):

FYI, the new Endpoint.choices() has been merged in master branch of pynetbox:

https://pynetbox.readthedocs.io/en/latest/endpoint.html#pynetbox.core.endpoint.Endpoint.choices

>>> from pprint import pprint
>>> pprint(netbox.ipam.ip_addresses.choices())
{'role': [{'display_name': 'Secondary', 'value': 20},
          {'display_name': 'VIP', 'value': 40},
          {'display_name': 'VRRP', 'value': 41},
          {'display_name': 'Loopback', 'value': 10},
          {'display_name': 'GLBP', 'value': 43},
          {'display_name': 'CARP', 'value': 44},
          {'display_name': 'HSRP', 'value': 42},
          {'display_name': 'Anycast', 'value': 30}],
 'status': [{'display_name': 'Active', 'value': 1},
            {'display_name': 'Reserved', 'value': 2},
            {'display_name': 'Deprecated', 'value': 3},
            {'display_name': 'DHCP', 'value': 5}]}
>>>
@markkuleinio commented on GitHub (Nov 12, 2019): FYI, the new `Endpoint.choices()` has been merged in `master` branch of [pynetbox](https://github.com/digitalocean/pynetbox): https://pynetbox.readthedocs.io/en/latest/endpoint.html#pynetbox.core.endpoint.Endpoint.choices ``` >>> from pprint import pprint >>> pprint(netbox.ipam.ip_addresses.choices()) {'role': [{'display_name': 'Secondary', 'value': 20}, {'display_name': 'VIP', 'value': 40}, {'display_name': 'VRRP', 'value': 41}, {'display_name': 'Loopback', 'value': 10}, {'display_name': 'GLBP', 'value': 43}, {'display_name': 'CARP', 'value': 44}, {'display_name': 'HSRP', 'value': 42}, {'display_name': 'Anycast', 'value': 30}], 'status': [{'display_name': 'Active', 'value': 1}, {'display_name': 'Reserved', 'value': 2}, {'display_name': 'Deprecated', 'value': 3}, {'display_name': 'DHCP', 'value': 5}]} >>> ```
Author
Owner

@markkuleinio commented on GitHub (Nov 16, 2019):

I see pynetbox 4.1.0 has now been released with the .choices() method in the endpoint objects (among other enhancements).

@markkuleinio commented on GitHub (Nov 16, 2019): I see pynetbox [4.1.0](https://github.com/digitalocean/pynetbox/releases) has now been released with the `.choices()` method in the endpoint objects (among other enhancements).
Author
Owner

@markkuleinio commented on GitHub (Dec 15, 2019):

Just to show an example of Endpoint.choices() with the string values in 2.7-beta1, works fine:

>>> pynetbox.__version__
'4.2.2'
>>> netbox.version
'2.7'
>>> pprint(netbox.ipam.ip_addresses.choices())
{'role': [{'display_name': 'Loopback', 'value': 'loopback'},
          {'display_name': 'Secondary', 'value': 'secondary'},
          {'display_name': 'Anycast', 'value': 'anycast'},
          {'display_name': 'VIP', 'value': 'vip'},
          {'display_name': 'VRRP', 'value': 'vrrp'},
          {'display_name': 'HSRP', 'value': 'hsrp'},
          {'display_name': 'GLBP', 'value': 'glbp'},
          {'display_name': 'CARP', 'value': 'carp'}],
 'status': [{'display_name': 'Active', 'value': 'active'},
            {'display_name': 'Reserved', 'value': 'reserved'},
            {'display_name': 'Deprecated', 'value': 'deprecated'},
            {'display_name': 'DHCP', 'value': 'dhcp'}]}
>>>
@markkuleinio commented on GitHub (Dec 15, 2019): Just to show an example of `Endpoint.choices()` with the string values in 2.7-beta1, works fine: ``` >>> pynetbox.__version__ '4.2.2' >>> netbox.version '2.7' >>> pprint(netbox.ipam.ip_addresses.choices()) {'role': [{'display_name': 'Loopback', 'value': 'loopback'}, {'display_name': 'Secondary', 'value': 'secondary'}, {'display_name': 'Anycast', 'value': 'anycast'}, {'display_name': 'VIP', 'value': 'vip'}, {'display_name': 'VRRP', 'value': 'vrrp'}, {'display_name': 'HSRP', 'value': 'hsrp'}, {'display_name': 'GLBP', 'value': 'glbp'}, {'display_name': 'CARP', 'value': 'carp'}], 'status': [{'display_name': 'Active', 'value': 'active'}, {'display_name': 'Reserved', 'value': 'reserved'}, {'display_name': 'Deprecated', 'value': 'deprecated'}, {'display_name': 'DHCP', 'value': 'dhcp'}]} >>> ```
Author
Owner

@kobayashi commented on GitHub (Mar 8, 2020):

For swagger, we need to change label to display_name in CustomChoiceFieldInspector in addition to the ChoiceField.

@kobayashi commented on GitHub (Mar 8, 2020): For swagger, we need to change `label` to `display_name` in CustomChoiceFieldInspector in addition to the ChoiceField.
Author
Owner

@jeremystretch commented on GitHub (Mar 12, 2020):

For swagger, we need to change label to display_name in CustomChoiceFieldInspector in addition to the ChoiceField.

IIRC at some point we had discussed moving the other way: changing value to display_name in the ChoiceField serializer. I've opened #4358 to track this separately.

@jeremystretch commented on GitHub (Mar 12, 2020): > For swagger, we need to change `label` to `display_name` in CustomChoiceFieldInspector in addition to the ChoiceField. IIRC at some point we had discussed moving the other way: changing `value` to `display_name` in the ChoiceField serializer. I've opened #4358 to track this separately.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2797