netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
538 stars 165 forks source link

Choices are not returned when the API token can PUT but not POST on an endpoint #591

Open BenoitKnecht opened 8 months ago

BenoitKnecht commented 8 months ago

pynetbox version

v7.1.0

NetBox version

v3.4.3

Python version

3.9

Steps to Reproduce

Using an API token that cannot POST on the /dcim/devices/ endpoint for instance, try getting choices using

nb.dcim.devices.choices()

Expected Behavior

A list of choices is returned.

Observed Behavior

ValueError: Unexpected format in the OPTIONS response at https://netbox.example.com/api/dcim/devices
BenoitKnecht commented 8 months ago

I can submit a PR for a simple fix that would get the choices from the .actions.PUT sections returned by the OPTIONS request when .actions.POST is missing.

markkuleinio commented 8 months ago

Just wondering: what is the use case for fetching the choices list when there is no possibility anyway to use the choice values to create/edit objects?

Or do I miss something about POST vs PUT

BenoitKnecht commented 8 months ago

Just wondering: what is the use case for fetching the choices list when there is no possibility anyway to use the choice values to create/edit objects?

Or do I miss something about POST vs PUT

@markkuleinio With POST you create new objects, and with PUT you update existing objects. So fetching choices is useful in that latter case too. :slightly_smiling_face:

markkuleinio commented 8 months ago

Right, so the use case is a user that doesn't have create access but has modify access.

BenoitKnecht commented 1 week ago

Hey, could someone review (and ideally merge) the PR above (#592)? I'm still hitting this bug whenever I use Ansible to interact with Netbox.