Skip to content
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

possibility to GET Custom_fields from API #1841

Closed
ZdenekPesek opened this issue Jan 26, 2018 · 5 comments
Closed

possibility to GET Custom_fields from API #1841

ZdenekPesek opened this issue Jan 26, 2018 · 5 comments
Labels
status: duplicate This issue has already been raised type: feature Introduction of new functionality to the application

Comments

@ZdenekPesek
Copy link

Issue type

[ x] Feature request
[ ] Bug report
[ ] Documentation

Environment

Python 2.7.12
Netbox 2.2.8

Description

As there is possible to define a lot of IPAM Custom_Fields, it would be useful to have also possibility to GET all those key/value/label back from API, same as static_choice.

Use case:
I have YAML file which can POST new IP records in batch, i need to define the Custom_Fields for every record. But i am not able to define which value corresponds with which label, therefore i would like to make a GET call for it before and then i can see which value is what label and can complete YAML file with proper Custom_Fields values.

@lampwins
Copy link
Contributor

To add to this, the idea is that custom fields with a type of Selection should have their preset choices available in the API. This functionality would be similar to the _choices API endpoints already present today.

I do not believe this should introduce any other API functionality surrounding custom fields.

@jeremystretch
Copy link
Member

@PacketBucket Could you please provide an example API request and response illustrating the functionality being proposed?

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application API change status: revisions needed This issue requires additional information to be actionable labels Jan 26, 2018
@cimnine
Copy link
Contributor

cimnine commented Jan 29, 2018

I asked for this as well in #1792.

As a concrete proposal I could imagine an endpoint https://netbox/api/ipam/ip-addresses/_choices/, which would return all the possible values with their respective key in a format similar to https://netbox/api/ipam/_choices/.

@ZdenekPesek
Copy link
Author

Maybe i would have two proposals and we can agree on what is more suitable for us.

As custom fields are defined on one place https://netbox/admin/extras/customfield/
I would imagine to GET all those info from https://netbox/api/extras/customfield/

This is approximate model what I would imagine as output, it is yaml just for better reading
(other types as URL should use same model, I'm not familiar with defining it yet) and should return all custom fields which have been defined, as for example:

---
hostname:
  required: true
  type: Text
  values:
  models:
    - ipaddress
status_scan:
  required: false
  type: Boolean
  values:
  models:
    - ipaddress
    - prefix 
owner:
  required: true
  type: Selection
  values:
    - value: ICT
      label: 12
    - value: Finance
      label: 31
  models:
    - prefix
    - ipaddress
    - vlan
anything:
  required: false
  type: Text
  values:
  models:
    - ipaddress
    - device

Second thought is more the same as _choice in every API item or how to say... (circuit, dcim, extras, ..., virtualization), every such an item would have its own /customfield/ and output would give us all custom fields according models defined in objects for each custom field in /admin/extras/customfield/.
If I take two custom fields from above that would mean:

Custom Field "owner"
Objects:
ipam > prefix
ipam > ipaddress
ipam > vlan

Custom Field "anything"
Objects:
ipam > ipaddress
dcim > device

using GET from https://netbox/api/ipam/customfield/ would return both custom fields above as both have objects ipam in it,

---
owner:
  required: true
  type: Selection
  values:
    - value: ICT
      label: 12
    - value: Finance
      label: 31
  models:
    - prefix
    - ipaddress
    - vlan
anything:
  required: false
  type: Text
  values:
  models:
    - ipaddress
    - device

on other hand https://netbox/api/dcim/customfield/ would return just "anything" custom field

---
anything:
  required: false
  type: Text
  values:
  models:
    - ipaddress
    - device

as i now got all those info together, i think first proposal does make me more sense, and that just from one reason, to have all fields available from one url.
I thing its better to have one request and GET all of the data, than iterate over bunch of URLs with the more less same output.

Just let me know your thoughts, ideas.

@jeremystretch
Copy link
Member

I agree with @cimnine, this looks like it mostly overlaps with #1792 so I'm going to mark it as a duplicate. It will be linked from the other issue though, so thank you for providing the example cases.

@jeremystretch jeremystretch added status: duplicate This issue has already been raised and removed API change status: revisions needed This issue requires additional information to be actionable labels Jan 30, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: duplicate This issue has already been raised type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

4 participants