Improve API for setting custom fields with object type #9510

Open
opened 2025-12-29 20:50:48 +01:00 by adam · 0 comments
Owner

Originally created by @peteeckel on GitHub (Apr 22, 2024).

NetBox version

v3.7.5

Feature type

New functionality

Proposed functionality

Currently, selecting an object for a custom field using the API requires the knowledge of the pk of that object. This makes selecting objects as custom field values a two-step operation in cases where the pk is not known yet:

  1. Look up the target object to get the pk
  2. Create or update the object value with the information obtained in step 1.
curl -X "POST" "https://netbox.example.com/api/ipam/ip-addresses/" \
     -H 'Authorization: Token xxxxxxxxxxxxxx' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "address": "10.1.1.2/24",
  "custom_fields": {
    "object_id": "1"
  }
}'

This proposal is to extend the API functionality for custom fields in a way that makes it possible to assign custom field objects analogous to other foreign key objects, i.e. using a filter condition determined by the object type's filterset:

curl -X "POST" "https://netbox.example.com/api/ipam/ip-addresses/" \
     -H 'Authorization: Token xxxxxxxxxxxxxx' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "address": "10.1.1.2/24",
  "custom_fields": {
    "object": {
      "name": "object name"
    }
  }
}'

Use case

Any use case involving setting custom field values for object type values using the API, Ansible, or pynetbox would benefit from this simplified way of assigning object values.

Database changes

None that I'm aware of. The implementation should be feasible within the serializer code for custom field objects.

External dependencies

none~

Originally created by @peteeckel on GitHub (Apr 22, 2024). ### NetBox version v3.7.5 ### Feature type New functionality ### Proposed functionality Currently, selecting an object for a custom field using the API requires the knowledge of the `pk` of that object. This makes selecting objects as custom field values a two-step operation in cases where the `pk` is not known yet: 1. Look up the target object to get the `pk` 2. Create or update the object value with the information obtained in step 1. ```bash curl -X "POST" "https://netbox.example.com/api/ipam/ip-addresses/" \ -H 'Authorization: Token xxxxxxxxxxxxxx' \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "address": "10.1.1.2/24", "custom_fields": { "object_id": "1" } }' ``` This proposal is to extend the API functionality for custom fields in a way that makes it possible to assign custom field objects analogous to other foreign key objects, i.e. using a filter condition determined by the object type's `filterset`: ```bash curl -X "POST" "https://netbox.example.com/api/ipam/ip-addresses/" \ -H 'Authorization: Token xxxxxxxxxxxxxx' \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "address": "10.1.1.2/24", "custom_fields": { "object": { "name": "object name" } } }' ``` ### Use case Any use case involving setting custom field values for object type values using the API, Ansible, or `pynetbox` would benefit from this simplified way of assigning object values. ### Database changes None that I'm aware of. The implementation should be feasible within the serializer code for custom field objects. ### External dependencies none\~
adam added the type: featurenetboxneeds milestonestatus: backlogcomplexity: high labels 2025-12-29 20:50:48 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9510