Skip to content

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 #13746

@matheuskshn

Description

@matheuskshn

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": "[email protected]",
      "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.

Metadata

Metadata

Assignees

Labels

severity: mediumResults in substantial degraded or broken functionality for specfic workflowsstatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions