jasonyates / netbox-documents

Plugin to manage site, circuit and device diagrams and documents in Netbox
Apache License 2.0
131 stars 20 forks source link

Insert Nested Documents objects in REST API for assigned models #50

Open marcosmas28 opened 10 months ago

marcosmas28 commented 10 months ago

Hi,

With the template_content.py script we can extend the GUI of the assigned objects (Sites, Locations, Devices, Circuits) to show the documents they have attached.

How could we do the same for the REST API interface? For instance, when I request http:///api/dcim/devices// I would like to get some info about the documents this device has attached.

Example (see last part "documents"):

HTTP 200 OK
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 65,
    "url": "http://<NETBOX_URL>/api/dcim/devices/65/",
    "display": "7750SR_01",
    "name": "7750SR_01",
    "device_type": {
        "id": 21,
        "url": "http://<NETBOX_URL>/api/dcim/device-types/21/",
        "display": "7750 SR-12",
        "manufacturer": {
            "id": 4,
            "url": "http://<NETBOX_URL>/api/dcim/manufacturers/4/",
            "display": "Nokia",
            "name": "Nokia",
            "slug": "nokia"
        },
        "model": "7750 SR-12",
        "slug": "7750-sr-12"
    },
    "role": {
        "id": 3,
        "url": "http://<NETBOX_URL>/api/dcim/device-roles/3/",
        "display": "ROUTERS",
        "name": "ROUTERS",
        "slug": "routers"
    },
    "documents":{
        "id": <my_device_document_id>,
        "url": <my_device_document_url>,
        "name": <my_device_document_name>,
        "document_type": <my_device_document_type>
    },
...

Thanks for the guidance!