Accept nested parameters when setting related objects via the API #3077
Labels
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
Milestone
Environment
Proposed Functionality
I'd like to explore the possibility of accepting arbitrary parameters describing a related object as an alternative to providing the related object's unique primary key when when creating/updating objects via NetBox's REST API. For example, creating a device currently accepts a request like this:
This requires the client to have prior knowledge of the device type ID and the rack ID, which typically will require separate requests made earlier. It may be feasible to extend
WritableNestedSerializer
to alternatively accept nested parameters that can be converted to a queryset. For example:The serializer for the
device_type
field would translate the provided JSON object into a queryset:The serializer would either assign the returned object to the field, or raise a validation error if the object is not found (or if multiple objects are found because the given attributes were not sufficiently unique).
The current behavior of accepting an integer primary key value will be retained as an alternative to this approach: Attributes will be evaluated only if the value provided for a field is a dictionary.
Use Case
Supporting this approach will obviate the need for precursory API queries to determine the primary key values of any related objects.
Database Changes
N/A
External Dependencies
N/A
The text was updated successfully, but these errors were encountered: