Add possibility to limit API response fields #620

Closed
opened 2025-12-29 16:23:54 +01:00 by adam · 3 comments
Owner

Originally created by @Armadill0 on GitHub (Jan 10, 2017).

I'm currently using the API of Netbox to query it from a bash-completion script, which makes it much easier to find the device you want e.g. ssh to.

The problem ist, that I need to do this via /api/dcim/devices (because it's the only API endpoint which can search for device names) which can be limited by the q parameter to search through all hosts.
Although this massively speeds up the lookup if the user has a value for "q", it could be much faster if the results are higher than 150-200 devices. I assume the reason is, because the response for 200 devices also includes all information for this device.
This blows the response up to a size of several hundred kbytes, which need to be transfered and parsed on the client (by a small python script in my case, before the results are being forwarded to the bash-completion script).

So I searched for a possibility to limit the response of the API only to the "name" field, which would save most of the data which is always transfered if you do any API request.

What I found is this: https://github.com/wimglenn/djangorestframework-queryfields

Is it possible to integrate this Django extension or something similar to the API so we can restrict the returned data to what we really need?

Originally created by @Armadill0 on GitHub (Jan 10, 2017). I'm currently using the API of Netbox to query it from a bash-completion script, which makes it much easier to find the device you want e.g. ssh to. The problem ist, that I need to do this via /api/dcim/devices (because it's the only API endpoint which can search for device names) which can be limited by the q parameter to search through all hosts. Although this massively speeds up the lookup if the user has a value for "q", it could be much faster if the results are higher than 150-200 devices. I assume the reason is, because the response for 200 devices also includes all information for this device. This blows the response up to a size of several hundred kbytes, which need to be transfered and parsed on the client (by a small python script in my case, before the results are being forwarded to the bash-completion script). So I searched for a possibility to limit the response of the API only to the "name" field, which would save most of the data which is always transfered if you do any API request. What I found is this: https://github.com/wimglenn/djangorestframework-queryfields Is it possible to integrate this Django extension or something similar to the API so we can restrict the returned data to what we really need?
adam closed this issue 2025-12-29 16:23:54 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 10, 2017):

I'll keep this request in mind, however there won't be any significant changes made to the API until v2.0, at which point the entire thing will likely be overhauled (see #113).

@jeremystretch commented on GitHub (Jan 10, 2017): I'll keep this request in mind, however there won't be any significant changes made to the API until v2.0, at which point the entire thing will likely be overhauled (see #113).
Author
Owner

@mayuresh82 commented on GitHub (Aug 14, 2018):

Was this feature ever added to any of the v2.x releases ?

@mayuresh82 commented on GitHub (Aug 14, 2018): Was this feature ever added to any of the v2.x releases ?
Author
Owner

@Armadill0 commented on GitHub (Sep 7, 2018):

@mayuresh82 I don't think so.

@jeremystretch Hi Jeremy, any chance you could take this into account?

I'm currently trying to speedup my scripts by rewriting them in Go, but the majority of time of roughly two seconds to get a list of 200 devices is being taken by the Netbox request itself.

@Armadill0 commented on GitHub (Sep 7, 2018): @mayuresh82 I don't think so. @jeremystretch Hi Jeremy, any chance you could take this into account? I'm currently trying to speedup my scripts by rewriting them in Go, but the majority of time of roughly two seconds to get a list of 200 devices is being taken by the Netbox request itself.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#620