Add API filters for all models #973

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

Originally created by @mattburgess on GitHub (May 18, 2017).

Issue type: bug report

Python version: 2.7.13
NetBox version: 2.0.3

Given the following device-roles:

$ curl http://192.168.33.34/api/dcim/device-roles/

{"count":2,"next":null,"previous":null,"results":[{"id":1,"name":"Chassis","slug":"chassis","color":"ff0000"},{"id":2,"name":"OpenStack Node","slug":"openstacknode","color":"008000"}]}

I'd expect the following query to return just 1 device-role (as per other similar queries against other objects that work as expected):
$ curl http://192.168.33.34/api/dcim/device-roles/?name=Chassis

{"count":2,"next":null,"previous":null,"results":[{"id":1,"name":"Chassis","slug":"chassis","color":"ff0000"},{"id":2,"name":"OpenStack Node","slug":"openstacknode","color":"008000"}]}

Originally created by @mattburgess on GitHub (May 18, 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 report <!-- 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.13 **NetBox version:** 2.0.3 <!-- 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. --> Given the following device-roles: ```$ curl http://192.168.33.34/api/dcim/device-roles/``` ```{"count":2,"next":null,"previous":null,"results":[{"id":1,"name":"Chassis","slug":"chassis","color":"ff0000"},{"id":2,"name":"OpenStack Node","slug":"openstacknode","color":"008000"}]}``` I'd expect the following query to return just 1 device-role (as per other similar queries against other objects that work as expected): ```$ curl http://192.168.33.34/api/dcim/device-roles/?name=Chassis``` ```{"count":2,"next":null,"previous":null,"results":[{"id":1,"name":"Chassis","slug":"chassis","color":"ff0000"},{"id":2,"name":"OpenStack Node","slug":"openstacknode","color":"008000"}]}```
adam added the type: feature label 2025-12-29 16:27:30 +01:00
adam closed this issue 2025-12-29 16:27:31 +01:00
Author
Owner

@mattburgess commented on GitHub (May 19, 2017):

Looking at the code, it seems these objects just need filters writing to enable querying. I'll see if I can have a go at this over the weekend unless there's particular reasons why these filters haven't already been implemented?

My use case is that I'm trying to fully populate our NetBox instance using the API and a bunch of YAML data.

When it comes to adding a device-type, it has a relationship with manufacturer so my code has to look up the manufacturer ID given its name so it can satisfy that relationship. Similarly, when adding a device then the device-role has to be looked up by name.

@mattburgess commented on GitHub (May 19, 2017): Looking at the code, it seems these objects just need filters writing to enable querying. I'll see if I can have a go at this over the weekend unless there's particular reasons why these filters haven't already been implemented? My use case is that I'm trying to fully populate our NetBox instance using the API and a bunch of YAML data. When it comes to adding a device-type, it has a relationship with manufacturer so my code has to look up the manufacturer ID given its name so it can satisfy that relationship. Similarly, when adding a device then the device-role has to be looked up by name.
Author
Owner

@DerekTBrown commented on GitHub (May 29, 2017):

Am I correct in saying that query filters aren't implemented for any model?

@DerekTBrown commented on GitHub (May 29, 2017): Am I correct in saying that query filters aren't implemented for any model?
Author
Owner

@jeremystretch commented on GitHub (Jun 19, 2017):

Implemented query filters for all remaining models in 87e5687

@jeremystretch commented on GitHub (Jun 19, 2017): Implemented query filters for all remaining models in 87e5687
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#973