Include request ID in REST API responses #7387

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

Originally created by @roberteriksen1979 on GitHub (Dec 20, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

3.2.5

Feature type

Change to existing functionality

Proposed functionality

When changing an item, using the REST API, could it be possible to get the changelog id returned immediately?
f.x as an X-ChangeId header or similar?

Use case

When multiple systems update various properties of the same entities in Netbox, we can not always rely on simply getting the latest change via the extras/object-changes endpoint.
Also getting the change id immediately would save an otherwise unnecessary API request.

Database changes

No response

External dependencies

No response

Originally created by @roberteriksen1979 on GitHub (Dec 20, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version 3.2.5 ### Feature type Change to existing functionality ### Proposed functionality When changing an item, using the REST API, could it be possible to get the changelog id returned immediately? f.x as an X-ChangeId header or similar? ### Use case When multiple systems update various properties of the same entities in Netbox, we can not always rely on simply getting the latest change via the extras/object-changes endpoint. Also getting the change id immediately would save an otherwise unnecessary API request. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:22:45 +01:00
adam closed this issue 2025-12-29 20:22:45 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 22, 2022):

When changing an item, using the REST API, could it be possible to get the changelog id returned immediately?

This could be feasible currently, however we need to consider future plans to generate changelog records outside of the request/response cycle (see #11202), which would inhibit us from returning the ObjectChange ID directly. (In this scenario, the ObjectChange would not be created until just after the response has been sent.) Additionally, bulk changes would result in the creation of multiple ObjectChanges, so we'd need a way to convey those.

Alternatively, we could attach to the API response the UUID of the request, which could then be used to query for all ObjectChange records relevant to the specific request.

@jeremystretch commented on GitHub (Dec 22, 2022): > When changing an item, using the REST API, could it be possible to get the changelog id returned immediately? This could be feasible currently, however we need to consider future plans to generate changelog records outside of the request/response cycle (see #11202), which would inhibit us from returning the ObjectChange ID directly. (In this scenario, the ObjectChange would not be created until just _after_ the response has been sent.) Additionally, bulk changes would result in the creation of multiple ObjectChanges, so we'd need a way to convey those. Alternatively, we could attach to the API response the UUID of the request, which could then be used to query for all ObjectChange records relevant to the specific request.
Author
Owner

@jeremystretch commented on GitHub (Jan 5, 2023):

Alternatively, we could attach to the API response the UUID of the request, which could then be used to query for all ObjectChange records relevant to the specific request.

I'm going to move this to "needs milestone" with the assumption that this is the preferred approach. Many changes can result in the creation of multiple new change records, and conveying them reliably and succinctly would be difficult. Returning the unique request ID is a lot more portable.

@jeremystretch commented on GitHub (Jan 5, 2023): > Alternatively, we could attach to the API response the UUID of the request, which could then be used to query for all ObjectChange records relevant to the specific request. I'm going to move this to "needs milestone" with the assumption that this is the preferred approach. Many changes can result in the creation of multiple new change records, and conveying them reliably and succinctly would be difficult. Returning the unique request ID is a lot more portable.
Author
Owner

@arthanson commented on GitHub (Jan 6, 2023):

Note: This would be similar to a correlation ID in logging (which might also be useful) There are two Django packages that do this that could be used for inspiration https://github.com/snok/django-guid and https://github.com/Polyconseil/django-cid

@arthanson commented on GitHub (Jan 6, 2023): **Note:** This would be similar to a correlation ID in logging (which might also be useful) There are two Django packages that do this that could be used for inspiration https://github.com/snok/django-guid and https://github.com/Polyconseil/django-cid
Author
Owner

@tyler-8 commented on GitHub (Jan 13, 2023):

Just to add - I think it makes sense for the request UUID to be returned as part of the response headers, rather than the payload itself. In other APIs where similar type of data is returned, headers seem to be the common pattern.

@tyler-8 commented on GitHub (Jan 13, 2023): Just to add - I think it makes sense for the request UUID to be returned as part of the response headers, rather than the payload itself. In other APIs where similar type of data is returned, headers seem to be the common pattern.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7387