[PR #3078] [MERGED] Enable dictionary specification of related objects in API #12499

Closed
opened 2025-12-29 22:21:55 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/3078
Author: @jeremystretch
Created: 4/17/2019
Status: Merged
Merged: 4/17/2019
Merged by: @jeremystretch

Base: develop-2.6Head: 3077-nested-api-writes


📝 Commits (4)

  • de7207d Enable dictionary specification of related objects in API
  • a108807 Add tests for WritableNestedSerializer
  • 655e488 Merge branch 'develop-2.6' into 3077-nested-api-writes
  • fd4c503 Add test for dict_to_filter_params

📊 Changes

6 files changed (+281 additions, -18 deletions)

View changed files

📝 CHANGELOG.md (+31 -0)
📝 docs/api/overview.md (+24 -11)
📝 netbox/utilities/api.py (+38 -5)
netbox/utilities/tests/test_api.py (+119 -0)
📝 netbox/utilities/tests/test_utils.py (+37 -2)
📝 netbox/utilities/utils.py (+32 -0)

📄 Description

Fixes: #3077

Previously, referencing a related object in an API request required knowing the primary key (integer ID) of that object. For example, when creating a new device, its rack would be specified as an integer:

{
    "name": "MyNewDevice",
    "rack": 123,
    ...
}

The NetBox API now supports referencing related objects by a set of sufficiently unique attributes:

{
    "name": "MyNewDevice",
    "rack": {
        "site": {
            "name": "Equinix DC6"
        },
        "name": "R204"
    },
    ...
}

Note that if the provided parameters do not return exactly one object, a validation error is raised.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/3078 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 4/17/2019 **Status:** ✅ Merged **Merged:** 4/17/2019 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop-2.6` ← **Head:** `3077-nested-api-writes` --- ### 📝 Commits (4) - [`de7207d`](https://github.com/netbox-community/netbox/commit/de7207de558d27934d3e46910da07d42278936f5) Enable dictionary specification of related objects in API - [`a108807`](https://github.com/netbox-community/netbox/commit/a10880753410abcbb788843037474a14b109a3e5) Add tests for WritableNestedSerializer - [`655e488`](https://github.com/netbox-community/netbox/commit/655e48823a1ab9f4a4370fb58e9253c8b57143e0) Merge branch 'develop-2.6' into 3077-nested-api-writes - [`fd4c503`](https://github.com/netbox-community/netbox/commit/fd4c5031c7afa66eb02411a180d36dbc6ee7102b) Add test for dict_to_filter_params ### 📊 Changes **6 files changed** (+281 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+31 -0) 📝 `docs/api/overview.md` (+24 -11) 📝 `netbox/utilities/api.py` (+38 -5) ➕ `netbox/utilities/tests/test_api.py` (+119 -0) 📝 `netbox/utilities/tests/test_utils.py` (+37 -2) 📝 `netbox/utilities/utils.py` (+32 -0) </details> ### 📄 Description ### Fixes: #3077 Previously, referencing a related object in an API request required knowing the primary key (integer ID) of that object. For example, when creating a new device, its rack would be specified as an integer: ``` { "name": "MyNewDevice", "rack": 123, ... } ``` The NetBox API now supports referencing related objects by a set of sufficiently unique attributes: ``` { "name": "MyNewDevice", "rack": { "site": { "name": "Equinix DC6" }, "name": "R204" }, ... } ``` Note that if the provided parameters do not return exactly one object, a validation error is raised. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:21:55 +01:00
adam closed this issue 2025-12-29 22:21:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12499