Enable adding/removing tags on an object via the REST API without re-declaring the entire set #63

Closed
opened 2026-04-05 16:21:25 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jeremystretch on 3/27/2026

NetBox version

v4.5.5

Feature type

New functionality

Proposed functionality

Currently, NetBox requires re-declaring the entire set of tags on an object when adding/removing tags. For example, consider a site which already has tags Alpha, Bravo, and Charlie. Adding a fourth tag, Delta, requires explicitly specifying all four tags:

{
    "tags": [
        {"name": "Alpha"},
        {"name": "Bravo"},
        {"name": "Charlie"},
        {"name": "Delta"}
    ]
}

This proposal would extend TaggableModelSerializer to introduce two new optional write-only fields, add_tags and remove_tags. This would allow the client to specify only the relevant tag when adding one (or more):

{
    "add_tags": [
        {"name": "Delta"}
    ]
}

Or when removing a tag(s):

{
    "remove_tags": [
        {"name": "Alpha"}
    ]
}

The response data would not include either add_tags or remove_tags, as these are write-only fields, but would include the updated tags list.

Passing a tag via remove_tags that is not already assigned to the object should not trigger a validation error. This behavior better accommodates the bulk removal of tags that may or may not already be assigned to objects.

Use case

This would obviate the need for a REST API client to first determine the set of tags already assigned to an object when adding or removing tags.

Database changes

N/A

External dependencies

N/A

*Originally created by @jeremystretch on 3/27/2026* ### NetBox version v4.5.5 ### Feature type New functionality ### Proposed functionality Currently, NetBox requires re-declaring the entire set of tags on an object when adding/removing tags. For example, consider a site which already has tags Alpha, Bravo, and Charlie. Adding a fourth tag, Delta, requires explicitly specifying all four tags: ```json { "tags": [ {"name": "Alpha"}, {"name": "Bravo"}, {"name": "Charlie"}, {"name": "Delta"} ] } ``` This proposal would extend `TaggableModelSerializer` to introduce two new optional write-only fields, `add_tags` and `remove_tags`. This would allow the client to specify only the relevant tag when adding one (or more): ```json { "add_tags": [ {"name": "Delta"} ] } ``` Or when removing a tag(s): ```json { "remove_tags": [ {"name": "Alpha"} ] } ``` The response data would not include either `add_tags` or `remove_tags`, as these are write-only fields, but would include the updated `tags` list. Passing a tag via `remove_tags` that is not already assigned to the object should not trigger a validation error. This behavior better accommodates the bulk removal of tags that may or may not already be assigned to objects. ### Use case This would obviate the need for a REST API client to first determine the set of tags already assigned to an object when adding or removing tags. ### Database changes N/A ### External dependencies N/A
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#63