-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Values for Selection Custom Fields via API #1792
Comments
I just learned that the behaviour I described was already discussed in #1297, yet no solution was proposed / implemented to get the primary keys of values via the API. Which would be important when the selection options change over time or when the PKs differ between independant instances of Netbox (e.g. staging/production). |
I ran into this same issue when trying to update a selection-based custom field I'm using through APIs (and pynetbox). I'm really trying to avoid custom fields whenever I can but I still need a few. In general I'd rather have a custom field with fixed selection options rather than a string to try to limit data diversity.. but without a programmatic way of changing selection values, it's getting a bit challenging.. |
We need to decide how to expose the custom field choices in the API. Currently, each app has a
We can't do One option would be to prepend |
I am also very much interested in this feature. |
I feel this should be its own API endpoint. Perhaps |
@jeremystretch I'd be fine with any way to lookup the '_choices' label using the value. Doesn't have to be pretty, just has to work. |
@jeremystretch If issue would be accepted, i got the following branch ready to be merged Grokzen/netbox@develop...Grokzen:feature/custom_field_choice_api_endpoint It would add a new API endpoint
External services can query all fields and cache them locally for a period of time, or they can look for a specific value each time and pass it into the next api call to POST an item. |
Awesome, i will put it up during the upcomming workweek |
@Grokzen & @jeremystretch |
Issue type
[X] Feature request
[ ] Bug report
[ ] Documentation
Environment
Description
As I already told on the mailing list, I would like to fill in the values of selection custom fields via the API.
I expected to provide the actual value of the field, i.e. the text I see in the dropdown of the GUI. But the API expects to get the ID of the option, rather than the value, and there seems to be no way of looking up the available (value,id)-pairs for a given selection custom fields. Also I would like to avoid hardcoding any (value,id)-pairs in my application, as it's not consistent across our different Netbox instances (local, staging, production) and it would be very fragile.
I see two solutions:
IMO both options could even live in parallel to each other: Whenever an integer is presented as value for a selection custom field, we can assume it's the ID of the value. Whenever it's a string, we can assume it's the text value and first has to be converted to the corresponding integer id.
Allowing to submit text values via the API instead of the actual IDs might imply that we don't allow the same text value on one given selection custom field twice.
The text was updated successfully, but these errors were encountered: