Netbox 2.0 API - no support for json_flat #942

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

Originally created by @InsaneSplash on GitHub (May 12, 2017).

After upgrading to version 2.0.x with the new API, it no longer supports the type json_flat. We use this format to sync the device and primary IP from Netbox in to Oxidized.

http://netbox/api/dcim/devices/?format=json_flat
{"detail":"Not found."}

Originally created by @InsaneSplash on GitHub (May 12, 2017). After upgrading to version 2.0.x with the new API, it no longer supports the type json_flat. We use this format to sync the device and primary IP from Netbox in to Oxidized. `http://netbox/api/dcim/devices/?format=json_flat` `{"detail":"Not found."}`
adam closed this issue 2025-12-29 16:27:08 +01:00
Author
Owner

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

This was a hack added a while back for reasons I don't entirely remember. We've ditched custom renderers entirely in the new API. Instead, you can either modify the API consumer to read regular (nested) JSON, or you can create an export template to generate data in whatever format you prefer. Here's an example:

{% for device in queryset %}{% if device.status == 1 and device.primary_ip %}{{ device.name }}:{{ device.device_type.manufacturer.slug}}
{% endif %}{% endfor %}

This will produce output like this:

abc-switch1:juniper
abc-switch2:juniper
xyz-switch1:cisco
...
@jeremystretch commented on GitHub (May 12, 2017): This was a hack added a while back for reasons I don't entirely remember. We've ditched custom renderers entirely in the new API. Instead, you can either modify the API consumer to read regular (nested) JSON, or you can create an [export template](http://netbox.readthedocs.io/en/stable/data-model/extras/#export-templates) to generate data in whatever format you prefer. Here's an example: ``` {% for device in queryset %}{% if device.status == 1 and device.primary_ip %}{{ device.name }}:{{ device.device_type.manufacturer.slug}} {% endif %}{% endfor %} ``` This will produce output like this: ``` abc-switch1:juniper abc-switch2:juniper xyz-switch1:cisco ... ```
Author
Owner

@InsaneSplash commented on GitHub (May 12, 2017):

OK. I'll need to bring this up with the Oxidized developer again to see if he will consider adding support for multi-tier json results.

The problem with Oxidized is that its JSON API is not able to read more than 1 level deep. Using the json_flat option allowed me to access the data set since its sometimes located 2 or more levels down. Since one maps the fields it receives from the returned information to a local variable, this functionality is lost.

    map:
      name: name
      ip: primary_ip4_address
      model: platform_slug
      group: tenant_slug
@InsaneSplash commented on GitHub (May 12, 2017): OK. I'll need to bring this up with the Oxidized developer again to see if he will consider adding support for multi-tier json results. The problem with Oxidized is that its JSON API is not able to read more than 1 level deep. Using the json_flat option allowed me to access the data set since its sometimes located 2 or more levels down. Since one maps the fields it receives from the returned information to a local variable, this functionality is lost. ``` map: name: name ip: primary_ip4_address model: platform_slug group: tenant_slug ```
Author
Owner

@InsaneSplash commented on GitHub (May 12, 2017):

I did end up building a export template, which I used to manually get things up and running though but would prefer a more automated solution. I also don't want the template to necessary be available to all who use the system. I'll have to see what I can do to get around this.

@InsaneSplash commented on GitHub (May 12, 2017): I did end up building a export template, which I used to manually get things up and running though but would prefer a more automated solution. I also don't want the template to necessary be available to all who use the system. I'll have to see what I can do to get around this.
Author
Owner

@btimmerhuis commented on GitHub (Aug 16, 2017):

@InsaneSplash Could you share the export template? I'm trying the same but can't get the template right. All my attempts result in a JSON::ParserError.

@btimmerhuis commented on GitHub (Aug 16, 2017): @InsaneSplash Could you share the export template? I'm trying the same but can't get the template right. All my attempts result in a JSON::ParserError.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#942