Output nested custom fields on API requests #4922

Closed
opened 2025-12-29 19:22:18 +01:00 by adam · 1 comment
Owner

Originally created by @ghost on GitHub (May 18, 2021).

NetBox version

v2.11.3

Feature type

Change to existing functionality

Proposed functionality

When querying via API for a device (for example) the device's custom_fields data is presented but any of the linked models' (platform or tenant for example) custom_fields data is not presented.

Current API response (partial)

{
  "id": 1,
  "name": "my test device",
  "custom_fields": {
    "device_custom_field": "some data"
  },
  "tenant": {
...
    "name": "my tenant",
  },
  "platform": {
...
    "name": "my platform",
  },
  "site": {
...
    "name": "my site",
  }
}

Desired API response

{
  "id": 1,
  "name": "my test device",
  "custom_fields": {
    "device_custom_field": "some device data"
  },
  "tenant": {
...
    "custom_fields": {
      "tenant_custom_field": "some tenant data"
    },
    "name": "my tenant",
  },
  "platform": {
...
    "custom_fields": {
      "platform_custom_field": "some platform data"
    },
    "name": "my platform",
  },
  "site": {
...
    "custom_fields": {
      "site_custom_field": "some site data"
    },
    "name": "my site",
  }
}

Use case

In my particular use case we have some custom fields applied to multiple models and are also using the netbox ansible plugin.

The plugin is using the device and VM API responses as is when coupled with the compose feature, we'd like to have those values presented when using ansible for a few use cases we have.

We're currently using the config context for this data to be presented but it doesn't scale up and gets difficult to maintain.

Database changes

No response

External dependencies

No response

Originally created by @ghost on GitHub (May 18, 2021). ### NetBox version v2.11.3 ### Feature type Change to existing functionality ### Proposed functionality When querying via API for a device (for example) the device's `custom_fields` data is presented but any of the linked models' (`platform` or `tenant` for example) `custom_fields` data is not presented. Current API response (partial) ```json { "id": 1, "name": "my test device", "custom_fields": { "device_custom_field": "some data" }, "tenant": { ... "name": "my tenant", }, "platform": { ... "name": "my platform", }, "site": { ... "name": "my site", } } ``` Desired API response ```json { "id": 1, "name": "my test device", "custom_fields": { "device_custom_field": "some device data" }, "tenant": { ... "custom_fields": { "tenant_custom_field": "some tenant data" }, "name": "my tenant", }, "platform": { ... "custom_fields": { "platform_custom_field": "some platform data" }, "name": "my platform", }, "site": { ... "custom_fields": { "site_custom_field": "some site data" }, "name": "my site", } } ``` ### Use case In my particular use case we have some custom fields applied to multiple models and are also using the netbox ansible plugin. The plugin is using the device and VM API responses as is when coupled with the compose feature, we'd like to have those values presented when using ansible for a few use cases we have. We're currently using the config context for this data to be presented but it doesn't scale up and gets difficult to maintain. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 19:22:18 +01:00
adam closed this issue 2025-12-29 19:22:18 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 18, 2021):

Related objects are intentionally limited in the amount of data being conveyed to ensure optimal API performance. Your API consumer can make separate calls to retrieve the custom field data for related objects where necessary. Please consider opening a discussion if you'd like assistance with this.

@jeremystretch commented on GitHub (May 18, 2021): Related objects are intentionally limited in the amount of data being conveyed to ensure optimal API performance. Your API consumer can make separate calls to retrieve the custom field data for related objects where necessary. Please consider opening a [discussion](https://github.com/netbox-community/netbox/discussions) if you'd like assistance with this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4922