API v2: GET Request > url field - does not include port #956

Closed
opened 2025-12-29 16:27:15 +01:00 by adam · 2 comments
Owner

Originally created by @troxil on GitHub (May 16, 2017).

Issue type: Bug

Python version: 2.7.6
NetBox version: 2.0.2

When using API with GET requests, responds with a url field that has a absolute path is including host, but no port.

Suggestion would be respond with relative path instead of absolutes.

E.G GET http://ipam.fqdn.internal:8081/api/dcim/devices/9
Response:

{
  "id": 9,
  "name": "Some Device",
  "display_name": "Some Device",
  "device_type": {
    "id": 9,
    "url": "http://ipam.fqdn.internal/api/dcim/device-types/9/",
    "manufacturer": {
      "id": 6,
      "url": "http://ipam.fqdn.internal/api/dcim/manufacturers/6/",
      "name": "Device",
      "slug": "device"
    },
    "model": "MODEL",
    "slug": "SLUG"
  },
... } 

configuration.py

# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
ALLOWED_HOSTS = ['ipam.fqdn.internal','192.168.1.10', 'ipam.fqdn.internal:8081']
Originally created by @troxil on GitHub (May 16, 2017). <!-- Please note: GitHub issues are to be used only for feature requests and bug reports. For installation assistance or general discussion, please join us on the mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please indicate "bug report" or "feature request" below. Be sure to search the existing set of issues (both open and closed) to see if a similar issue has already been raised. --> ### Issue type: Bug <!-- If filing a bug, please indicate the version of Python and NetBox you are running. (This is not necessary for feature requests.) --> **Python version: 2.7.6** **NetBox version: 2.0.2** <!-- If filing a bug, please record the exact steps taken to reproduce the bug and any errors messages that are generated. If filing a feature request, please precisely describe the data model or workflow you would like to see implemented, and provide a use case. --> When using API with GET requests, responds with a url field that has a absolute path is including host, but no port. Suggestion would be respond with relative path instead of absolutes. E.G GET http://ipam.fqdn.internal:8081/api/dcim/devices/9 Response: ```json { "id": 9, "name": "Some Device", "display_name": "Some Device", "device_type": { "id": 9, "url": "http://ipam.fqdn.internal/api/dcim/device-types/9/", "manufacturer": { "id": 6, "url": "http://ipam.fqdn.internal/api/dcim/manufacturers/6/", "name": "Device", "slug": "device" }, "model": "MODEL", "slug": "SLUG" }, ... } ``` configuration.py ```python # Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local'] ALLOWED_HOSTS = ['ipam.fqdn.internal','192.168.1.10', 'ipam.fqdn.internal:8081'] ```
adam closed this issue 2025-12-29 16:27:15 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 16, 2017):

The URLs for serialized objects are formed using Django REST Framework's HyperlinkedIdentityField, which determines the host for the URL based on the incoming request. It looks like your httpd isn't forwarding information about the port it's running on to the WSGI service behind it.

If you're using nginx, try adding the following to your location / block:

proxy_set_header Host $host:8081;

We want to ensure we always return absolute URLs from the API to minimize the burden on the client.

@jeremystretch commented on GitHub (May 16, 2017): The URLs for serialized objects are formed using Django REST Framework's [HyperlinkedIdentityField](http://www.django-rest-framework.org/api-guide/relations/#hyperlinkedidentityfield), which determines the host for the URL based on the incoming request. It looks like your httpd isn't forwarding information about the port it's running on to the WSGI service behind it. If you're using nginx, try adding the following to your `location /` block: ``` proxy_set_header Host $host:8081; ``` We want to ensure we always return absolute URLs from the API to minimize the burden on the client.
Author
Owner

@jeremystretch commented on GitHub (May 24, 2017):

Closing due to lack of activity.

@jeremystretch commented on GitHub (May 24, 2017): Closing due to lack of activity.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#956