When attempting to create a new IP and set custom fields using a POST request to the API, the custom fields are being created as null, even when values are provided in the request body #8605

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

Originally created by @matheuskshn on GitHub (Sep 12, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.6.1

Python version

3.9

Steps to Reproduce

Before encountering this issue, we upgraded our NetBox installation from version 2.6.4 to 3.6.1, following the guidelines provided in the official documentation.

  1. Initiate a POST request to create a new IP address, including custom field values, through the API endpoint (the exact endpoint has been obfuscated for security reasons). The command to initiate this request looks something like:
curl -k -X POST https://netbox.example.com/api/ipam/prefixes/87946/available-ips/ \
-H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
  "description": "Test Description",
    "custom_fields": {
      "A_strServiceRequest": " Test request",
      "B_strRequester": "Test",
      "C_strEmail": "test@example.com",
      "D_strPhoneNumber": "55555555"
   }
}'

POST Response:

{
  "id": 410889,
  "url": "https://netbox.example.com/api/ipam/ip-addresses/410889/",
  "display": "192.168.57.4/22",
  "family": {
    "value": 4,
    "label": "IPv4"
  },
  "address": "192.168.57.4/22",
  "vrf": null,
  "tenant": null,
  "status": {
    "value": "active",
    "label": "Active"
  },
  "role": null,
  "assigned_object_type": null,
  "assigned_object_id": null,
  "assigned_object": null,
  "nat_inside": null,
  "nat_outside": [],
  "dns_name": "",
  "description": "",
  "comments": "",
  "tags": [],
  "custom_fields": {
    "A_strServiceRequest": null,
    "B_strRequester": null,
    "C_strEmail": null,
    "D_strPhoneNumber": null,
    "E_strAdditionalInfo": null
  },
  "created": "2023-09-12T16:35:07.845659Z",
  "last_updated": "2023-09-12T16:35:07.845684Z"
}
  1. Note that the custom fields are returned as null in the response, indicating that they were not set correctly during the POST request.

  2. Now initiate a PATCH request to modify the allocated IP with new custom field values using a command similar to:

curl -k -X PATCH https://netbox.example.com/api/ipam/ip-addresses/410889/ \
-H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
  "custom_fields": {
    "A_strServiceRequest": "NewValue1",
    "B_strRequester": "NewValue2",
    "C_strEmail": "NewValue3",
    "D_strPhoneNumber": "NewValue4",
    "E_strAdditionalInfo": "NewValue5"
  }
}'

PATCH Response:

{
  "id": 410889,
  "url": "https://netbox.example.com/api/ipam/ip-addresses/410889/",
  "display": "192.168.57.4/22",
  "family": {
    "value": 4,
    "label": "IPv4"
  },
  "address": "192.168.57.4/22",
  "vrf": null,
  "tenant": null,
  "status": {
    "value": "active",
    "label": "Active"
  },
  "role": null,
  "assigned_object_type": null,
  "assigned_object_id": null,
  "assigned_object": null,
  "nat_inside": null,
  "nat_outside": [],
  "dns_name": "",
  "description": "",
  "comments": "",
  "tags": [],
  "custom_fields": {
    "A_strServiceRequest": "NewValue1",
    "B_strRequester": "NewValue2",
    "C_strEmail": "NewValue3",
    "D_strPhoneNumber": "NewValue4",
    "E_strAdditionalInfo": "NewValue5"
  },
  "created": "2023-09-12T16:35:07.845659Z",
  "last_updated": "2023-09-12T16:36:26.526444Z"
}
  1. Observe that the PATCH request successfully updates the custom field values, as reflected in the response.

Expected Behavior

The custom fields should have accepted and stored the values provided in the initial POST request, instead of being created as null.

Observed Behavior

The custom fields are created as null during the POST request, even though values were provided in the request body. However, the subsequent PATCH request can successfully modify these fields with new values.

Originally created by @matheuskshn on GitHub (Sep 12, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.6.1 ### Python version 3.9 ### Steps to Reproduce Before encountering this issue, we upgraded our NetBox installation from version 2.6.4 to 3.6.1, following the guidelines provided in the official documentation. 1. Initiate a POST request to create a new IP address, including custom field values, through the API endpoint (the exact endpoint has been obfuscated for security reasons). The command to initiate this request looks something like: ```sh curl -k -X POST https://netbox.example.com/api/ipam/prefixes/87946/available-ips/ \ -H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "description": "Test Description", "custom_fields": { "A_strServiceRequest": " Test request", "B_strRequester": "Test", "C_strEmail": "test@example.com", "D_strPhoneNumber": "55555555" } }' ``` #### POST Response: ```json { "id": 410889, "url": "https://netbox.example.com/api/ipam/ip-addresses/410889/", "display": "192.168.57.4/22", "family": { "value": 4, "label": "IPv4" }, "address": "192.168.57.4/22", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": null, "assigned_object_id": null, "assigned_object": null, "nat_inside": null, "nat_outside": [], "dns_name": "", "description": "", "comments": "", "tags": [], "custom_fields": { "A_strServiceRequest": null, "B_strRequester": null, "C_strEmail": null, "D_strPhoneNumber": null, "E_strAdditionalInfo": null }, "created": "2023-09-12T16:35:07.845659Z", "last_updated": "2023-09-12T16:35:07.845684Z" } ``` 2. Note that the custom fields are returned as null in the response, indicating that they were not set correctly during the POST request. 3. Now initiate a PATCH request to modify the allocated IP with new custom field values using a command similar to: ```sh curl -k -X PATCH https://netbox.example.com/api/ipam/ip-addresses/410889/ \ -H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "custom_fields": { "A_strServiceRequest": "NewValue1", "B_strRequester": "NewValue2", "C_strEmail": "NewValue3", "D_strPhoneNumber": "NewValue4", "E_strAdditionalInfo": "NewValue5" } }' ``` #### PATCH Response: ```json { "id": 410889, "url": "https://netbox.example.com/api/ipam/ip-addresses/410889/", "display": "192.168.57.4/22", "family": { "value": 4, "label": "IPv4" }, "address": "192.168.57.4/22", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": null, "assigned_object_id": null, "assigned_object": null, "nat_inside": null, "nat_outside": [], "dns_name": "", "description": "", "comments": "", "tags": [], "custom_fields": { "A_strServiceRequest": "NewValue1", "B_strRequester": "NewValue2", "C_strEmail": "NewValue3", "D_strPhoneNumber": "NewValue4", "E_strAdditionalInfo": "NewValue5" }, "created": "2023-09-12T16:35:07.845659Z", "last_updated": "2023-09-12T16:36:26.526444Z" } ``` 4. Observe that the PATCH request successfully updates the custom field values, as reflected in the response. ### Expected Behavior The custom fields should have accepted and stored the values provided in the initial POST request, instead of being created as null. ### Observed Behavior The custom fields are created as null during the POST request, even though values were provided in the request body. However, the subsequent PATCH request can successfully modify these fields with new values.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:38:49 +01:00
adam closed this issue 2025-12-29 20:38:49 +01:00
Author
Owner

@lg-dgo commented on GitHub (Sep 13, 2023):

I can confirm the described behavior in Netbox version 3.6.1. But not only the custom field values will be ignored, also standard fields, like tenant or dns_name will not be set.

In Netbox version 3.5.9 this error did not exist yet. Here it works as it should.

@lg-dgo commented on GitHub (Sep 13, 2023): I can confirm the described behavior in Netbox version 3.6.1. But not only the custom field values will be ignored, also standard fields, like tenant or dns_name will not be set. In Netbox version 3.5.9 this error did not exist yet. Here it works as it should.
Author
Owner

@JaedanC commented on GitHub (Sep 15, 2023):

I have noticed similar behaviour to OP regarding Selection fields.

I've tried setting custom Selection fields using POST and PATCH, (tried with value and label), and neither will update the field in 3.6.2-dev. It did work in 3.5.9.

@JaedanC commented on GitHub (Sep 15, 2023): I have noticed similar behaviour to OP regarding Selection fields. I've tried setting custom Selection fields using POST and PATCH, (tried with `value` and `label`), and neither will update the field in 3.6.2-dev. It did work in 3.5.9.
Author
Owner

@sc68cal commented on GitHub (Oct 3, 2023):

We seem to be hitting this in the Ansible netbox collection's CI

https://github.com/netbox-community/ansible_modules/actions/runs/6291719867/job/17080388389

@sc68cal commented on GitHub (Oct 3, 2023): We seem to be hitting this in the Ansible netbox collection's CI https://github.com/netbox-community/ansible_modules/actions/runs/6291719867/job/17080388389
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8605