Custom field's default value not assigned when adding device via API #9376

Closed
opened 2025-12-29 20:49:08 +01:00 by adam · 3 comments
Owner

Originally created by @diondohmen on GitHub (Mar 21, 2024).

Deployment Type

Self-hosted

NetBox Version

v3.7.4

Python Version

3.8

Steps to Reproduce

  1. Create custom field 'test' of type Boolean and attach to Device object
  2. Set a default value of true

image

  1. Add device via API url: /api/dcim/devices/ & payload:
{
    "name": "testdevice1234",
    "role": {"name": "Access Switch"},
    "site": {"name": "DC"},
    "device_type": {"model": "4500"},
    "status": "active"
}
  1. API response
    image

Expected Behavior

custom_field 'test' should have the value of true and not null

Observed Behavior

custom_field 'test' is assigned the value of null

When adding the device via the GUI, custom_field 'test' is actually pre-filled with the correct value of true
image

Originally created by @diondohmen on GitHub (Mar 21, 2024). ### Deployment Type Self-hosted ### NetBox Version v3.7.4 ### Python Version 3.8 ### Steps to Reproduce 1. Create custom field '**test**' of type _Boolean_ and attach to Device object 2. Set a default value of `true` ![image](https://github.com/netbox-community/netbox/assets/60485478/52495c87-4828-4d91-89a0-eda7a362866d) 3. Add device via API url: `/api/dcim/devices/` & payload: ``` { "name": "testdevice1234", "role": {"name": "Access Switch"}, "site": {"name": "DC"}, "device_type": {"model": "4500"}, "status": "active" } ``` 4. API response ![image](https://github.com/netbox-community/netbox/assets/60485478/ec28ec2a-1e74-424e-911a-ba5899c2fb18) ### Expected Behavior custom_field 'test' should have the value of **true** and not **null** ### Observed Behavior custom_field 'test' is assigned the value of **null** When adding the device via the GUI, custom_field 'test' is actually pre-filled with the correct value of **true** ![image](https://github.com/netbox-community/netbox/assets/60485478/6253c1b5-6cad-4f81-a3ef-6ca81b7e7433)
adam added the type: bugstatus: revisions neededseverity: low labels 2025-12-29 20:49:08 +01:00
adam closed this issue 2025-12-29 20:49:08 +01:00
Author
Owner

@Julio-Oliveira-Encora commented on GitHub (Apr 8, 2024):

I created a test field, as mentioned. After I added the device using the API (Swagger):

curl -X 'POST'
'http://localhost:8000/api/dcim/devices/'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-H 'X-CSRFTOKEN: CrDXXwTUEBZwDW4ST8CAPKNrNDSAVynb28Y9LtGh0Nnwh8JyKwQRboqQsECylZ0n'
-d '{
"name": "testdevice1234",
"role": {"name": "Access Switch"},
"site": {"name": "Site A"},
"device_type": {"model": "C9200-48P"},
"status": "active"
}'

The object was created, and the custom fields seem fine:

"custom_fields": {
"Test": true,
"foo": null
},

@Julio-Oliveira-Encora commented on GitHub (Apr 8, 2024): I created a test field, as mentioned. After I added the device using the API (Swagger): curl -X 'POST' \ 'http://localhost:8000/api/dcim/devices/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: CrDXXwTUEBZwDW4ST8CAPKNrNDSAVynb28Y9LtGh0Nnwh8JyKwQRboqQsECylZ0n' \ -d '{ "name": "testdevice1234", "role": {"name": "Access Switch"}, "site": {"name": "Site A"}, "device_type": {"model": "C9200-48P"}, "status": "active" }' The object was created, and the custom fields seem fine: "custom_fields": { "Test": true, "foo": null },
Author
Owner

@arthanson commented on GitHub (Apr 11, 2024):

@diondohmen Thank you for opening a bug report. As shown above we were unable to reproduce the reported behavior. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.

@arthanson commented on GitHub (Apr 11, 2024): @diondohmen Thank you for opening a bug report. As shown above we were unable to reproduce the reported behavior. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
Author
Owner

@jeremystretch commented on GitHub (Apr 19, 2024):

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@jeremystretch commented on GitHub (Apr 19, 2024): This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9376