[PR #2941] [MERGED] Closes #1792 - Add CustomFieldChoices API endpoint #12466

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/2941
Author: @Grokzen
Created: 2/28/2019
Status: Merged
Merged: 3/4/2019
Merged by: @jeremystretch

Base: develop-2.6Head: feature/custom_field_choice_api_endpoint


📝 Commits (3)

  • dcfa982 Add new api endpoint for CustomFieldChoices
  • 4a347bf Add changelog item for #1792
  • 35491db Add tests for CustomFieldchoiceAPI endpoint

📊 Changes

4 files changed (+70 additions, -3 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 netbox/extras/api/urls.py (+3 -0)
📝 netbox/extras/api/views.py (+34 -2)
📝 netbox/extras/tests/test_customfields.py (+32 -1)

📄 Description

Fixes: #1792

This PR implements a new API endpoint for CustomFieldChoices that enables a consumer of the API to make calls to get the Primary Key ID:s for each custom field choice that is implemented on the server.

The new API endpoint is /api/extras/_custom_field_choices/

Example API output

{
  ...
  "archiving.retention": {
    "Archiving 13 Months": 493,
    "Archiving 7 Years": 494,
    "Archiving 10 Years": 495,
    "Other": 496
  },
  "backup.database.dbfrequency": {
    "1 per day": 515,
    "1 per hour": 516
  },
  ...
}

If you have a external service that want to integrate and set custom field choice, right now you have to hardcode the field values on the external side of the API. This is not good as the values is probably different between different installations and not guaranteed to be consistent. With this PR implemented the workflow will be that the external party have to lookup all customfieldchoices that is interesting and cache them locally on their end and then when they make API calls and they want to set a customfield value to a choice, they us the ID they get out from this api endpoint. If you do not want to cache the values you can just lookup the ID before each call.


🔄 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/2941 **Author:** [@Grokzen](https://github.com/Grokzen) **Created:** 2/28/2019 **Status:** ✅ Merged **Merged:** 3/4/2019 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop-2.6` ← **Head:** `feature/custom_field_choice_api_endpoint` --- ### 📝 Commits (3) - [`dcfa982`](https://github.com/netbox-community/netbox/commit/dcfa9826d5817d05424709813c3978655d1d14a1) Add new api endpoint for CustomFieldChoices - [`4a347bf`](https://github.com/netbox-community/netbox/commit/4a347bf405a7a2ec0ebdfb51c0bf819c5b9ab3ca) Add changelog item for #1792 - [`35491db`](https://github.com/netbox-community/netbox/commit/35491dbeeaa8d5149f930cfd0358c35dcb4e8794) Add tests for CustomFieldchoiceAPI endpoint ### 📊 Changes **4 files changed** (+70 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `netbox/extras/api/urls.py` (+3 -0) 📝 `netbox/extras/api/views.py` (+34 -2) 📝 `netbox/extras/tests/test_customfields.py` (+32 -1) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED. --> ### Fixes: #1792 <!-- Please include a summary of the proposed changes below. --> This PR implements a new API endpoint for CustomFieldChoices that enables a consumer of the API to make calls to get the Primary Key ID:s for each custom field choice that is implemented on the server. The new API endpoint is `/api/extras/_custom_field_choices/` Example API output ``` { ... "archiving.retention": { "Archiving 13 Months": 493, "Archiving 7 Years": 494, "Archiving 10 Years": 495, "Other": 496 }, "backup.database.dbfrequency": { "1 per day": 515, "1 per hour": 516 }, ... } ``` If you have a external service that want to integrate and set custom field choice, right now you have to hardcode the field values on the external side of the API. This is not good as the values is probably different between different installations and not guaranteed to be consistent. With this PR implemented the workflow will be that the external party have to lookup all customfieldchoices that is interesting and cache them locally on their end and then when they make API calls and they want to set a customfield value to a choice, they us the ID they get out from this api endpoint. If you do not want to cache the values you can just lookup the ID before each call. --- <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:45 +01:00
adam closed this issue 2025-12-29 22:21:45 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12466