is_api_request() returns False if content type is not set to "application/json" #11437

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

Originally created by @jeremystretch on GitHub (Aug 1, 2025).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.3.5

Python Version

3.10

Steps to Reproduce

  1. Make a REST API GET request without specifying a content type:
curl -v -X GET \
-H "Authorization: Token $TOKEN" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/status/
  1. Inspect the response headers.

Expected Behavior

The response should include an API-Version header indicating the NetBox version. This can be verified by re-sending the above request with a Content-Type header:

curl -v -X GET \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/status/

Observed Behavior

The API-Version header is missing from the response.

The is_api_request() utility function is intended to return True for any request which qualifies as consuming the REST API. However, this happens only if the request has specified a Content-Type of application/json:

c7b68664f9/netbox/utilities/api.py (L55-L60)

The content type should not be a condition of qualifying as an API request.

Originally created by @jeremystretch on GitHub (Aug 1, 2025). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.3.5 ### Python Version 3.10 ### Steps to Reproduce 1. Make a REST API `GET` request without specifying a content type: ``` curl -v -X GET \ -H "Authorization: Token $TOKEN" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/status/ ``` 2. Inspect the response headers. ### Expected Behavior The response should include an `API-Version` header indicating the NetBox version. This can be verified by re-sending the above request with a `Content-Type` header: ``` curl -v -X GET \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/status/ ``` ### Observed Behavior The `API-Version` header is missing from the response. The `is_api_request()` utility function is intended to return True for any request which qualifies as consuming the REST API. However, this happens only if the request has specified a `Content-Type` of `application/json`: https://github.com/netbox-community/netbox/blob/c7b68664f9e48c0d70b18f4da8ae2c59b0c26e99/netbox/utilities/api.py#L55-L60 The content type should not be a condition of qualifying as an API request.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:45:14 +01:00
adam closed this issue 2025-12-29 21:45:15 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11437