Update REST API examples to current format #11022

Closed
opened 2025-12-29 21:39:16 +01:00 by adam · 5 comments
Owner

Originally created by @markkuleinio on GitHub (Apr 14, 2025).

Originally assigned to: @markkuleinio on GitHub.

Change Type

Correction

Area

Integrations/API

Proposed Changes

Example: https://netboxlabs.com/docs/netbox/en/stable/integrations/rest-api/#brief-format shows site information

    "site": {
        "id": 3,
        "url": "http://netbox/api/dcim/sites/17/",
        "name": "Site 23A",
        "slug": "site-23a"
    },

for a prefix, but in NetBox 4.2.x the syntax is something like

    "scope_type": "dcim.site",
    "scope_id": 1,
    "scope": {
        "id": 1,
        "url": "http://netbox/api/dcim/sites/1/",
        "display": "Test",
        "name": "Test",
        "slug": "test",
        "description": ""
    },
Originally created by @markkuleinio on GitHub (Apr 14, 2025). Originally assigned to: @markkuleinio on GitHub. ### Change Type Correction ### Area Integrations/API ### Proposed Changes Example: https://netboxlabs.com/docs/netbox/en/stable/integrations/rest-api/#brief-format shows `site` information ``` "site": { "id": 3, "url": "http://netbox/api/dcim/sites/17/", "name": "Site 23A", "slug": "site-23a" }, ``` for a prefix, but in NetBox 4.2.x the syntax is something like ``` "scope_type": "dcim.site", "scope_id": 1, "scope": { "id": 1, "url": "http://netbox/api/dcim/sites/1/", "display": "Test", "name": "Test", "slug": "test", "description": "" }, ```
adam added the status: acceptedtype: documentation labels 2025-12-29 21:39:16 +01:00
adam closed this issue 2025-12-29 21:39:16 +01:00
Author
Owner

@markkuleinio commented on GitHub (Apr 21, 2025):

I can try updating this.

@markkuleinio commented on GitHub (Apr 21, 2025): I can try updating this.
Author
Owner

@jnovinger commented on GitHub (Apr 25, 2025):

It's all yours, @markkuleinio . Thanks!

@jnovinger commented on GitHub (Apr 25, 2025): It's all yours, @markkuleinio . Thanks!
Author
Owner

@markkuleinio commented on GitHub (Apr 29, 2025):

How is it with the API-Version header nowadays, is it not present in 4.2.7 anymore?

$ curl -s -i https://demo.netbox.dev/api/ \
-H "Authorization: Token 60526d57184348a75291bce30ea2268134305230" \
-H "Accept: application/json; indent=4"
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 29 Apr 2025 12:59:05 GMT
Content-Type: application/json
Content-Length: 646
Connection: keep-alive
Vary: HX-Request, Accept-Language, Cookie, origin
Allow: GET, HEAD, OPTIONS
X-Request-ID: 5c3fc6a9-1fdd-4a8f-ab2e-4c31bd7a949b
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin
X-Frame-Options: SAMEORIGIN
Content-Language: en

{
    "circuits": "https://demo.netbox.dev/api/circuits/",
    "core": "https://demo.netbox.dev/api/core/",
    "dcim": "https://demo.netbox.dev/api/dcim/",
    "extras": "https://demo.netbox.dev/api/extras/",
    "ipam": "https://demo.netbox.dev/api/ipam/",
    "plugins": "https://demo.netbox.dev/api/plugins/",
    "status": "https://demo.netbox.dev/api/status/",
    "tenancy": "https://demo.netbox.dev/api/tenancy/",
    "users": "https://demo.netbox.dev/api/users/",
    "virtualization": "https://demo.netbox.dev/api/virtualization/",
    "vpn": "https://demo.netbox.dev/api/vpn/",
    "wireless": "https://demo.netbox.dev/api/wireless/"
}

https://netboxlabs.com/docs/netbox/en/stable/integrations/rest-api/#http-headers

X-Request-ID is there as documented.

@markkuleinio commented on GitHub (Apr 29, 2025): How is it with the `API-Version` header nowadays, is it not present in 4.2.7 anymore? ``` $ curl -s -i https://demo.netbox.dev/api/ \ -H "Authorization: Token 60526d57184348a75291bce30ea2268134305230" \ -H "Accept: application/json; indent=4" HTTP/1.1 200 OK Server: nginx/1.18.0 (Ubuntu) Date: Tue, 29 Apr 2025 12:59:05 GMT Content-Type: application/json Content-Length: 646 Connection: keep-alive Vary: HX-Request, Accept-Language, Cookie, origin Allow: GET, HEAD, OPTIONS X-Request-ID: 5c3fc6a9-1fdd-4a8f-ab2e-4c31bd7a949b X-Content-Type-Options: nosniff Referrer-Policy: same-origin Cross-Origin-Opener-Policy: same-origin X-Frame-Options: SAMEORIGIN Content-Language: en { "circuits": "https://demo.netbox.dev/api/circuits/", "core": "https://demo.netbox.dev/api/core/", "dcim": "https://demo.netbox.dev/api/dcim/", "extras": "https://demo.netbox.dev/api/extras/", "ipam": "https://demo.netbox.dev/api/ipam/", "plugins": "https://demo.netbox.dev/api/plugins/", "status": "https://demo.netbox.dev/api/status/", "tenancy": "https://demo.netbox.dev/api/tenancy/", "users": "https://demo.netbox.dev/api/users/", "virtualization": "https://demo.netbox.dev/api/virtualization/", "vpn": "https://demo.netbox.dev/api/vpn/", "wireless": "https://demo.netbox.dev/api/wireless/" } ``` https://netboxlabs.com/docs/netbox/en/stable/integrations/rest-api/#http-headers `X-Request-ID` is there as documented.
Author
Owner

@jeremystretch commented on GitHub (Apr 29, 2025):

Seems to be working AFAICT:

$ curl -s -i \
-H "Authorization: Token <...>" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
https://demo.netbox.dev/api/
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 29 Apr 2025 17:20:10 GMT
Content-Type: application/json
Content-Length: 646
Connection: keep-alive
Vary: HX-Request, Accept-Language, Cookie, origin
Allow: GET, HEAD, OPTIONS
X-Request-ID: abb3023d-5147-45ff-a531-be2ba43bbfc2
API-Version: 4.2  <--------------
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin
X-Frame-Options: SAMEORIGIN
Content-Language: en
@jeremystretch commented on GitHub (Apr 29, 2025): Seems to be working AFAICT: ``` $ curl -s -i \ -H "Authorization: Token <...>" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ https://demo.netbox.dev/api/ HTTP/1.1 200 OK Server: nginx/1.18.0 (Ubuntu) Date: Tue, 29 Apr 2025 17:20:10 GMT Content-Type: application/json Content-Length: 646 Connection: keep-alive Vary: HX-Request, Accept-Language, Cookie, origin Allow: GET, HEAD, OPTIONS X-Request-ID: abb3023d-5147-45ff-a531-be2ba43bbfc2 API-Version: 4.2 <-------------- X-Content-Type-Options: nosniff Referrer-Policy: same-origin Cross-Origin-Opener-Policy: same-origin X-Frame-Options: SAMEORIGIN Content-Language: en ```
Author
Owner

@markkuleinio commented on GitHub (Apr 29, 2025):

Right, thanks, I missed the Content-Type header that makes the difference (utilities.api.is_api_request() returns False in that case).

@markkuleinio commented on GitHub (Apr 29, 2025): Right, thanks, I missed the Content-Type header that makes the difference (`utilities.api.is_api_request()` returns `False` in that case).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11022