forked from netbox-community/netbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into develop-2.8
- Loading branch information
Showing
27 changed files
with
1,283 additions
and
1,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# API Filtering | ||
|
||
The NetBox API supports robust filtering of results based on the fields of each model. | ||
Generally speaking you are able to filter based on the attributes (fields) present in | ||
the response body. Please note however that certain read-only or metadata fields are not | ||
filterable. | ||
|
||
Filtering is achieved by passing HTTP query parameters and the parameter name is the | ||
name of the field you wish to filter on and the value is the field value. | ||
|
||
E.g. filtering based on a device's name: | ||
``` | ||
/api/dcim/devices/?name=DC-SPINE-1 | ||
``` | ||
|
||
## Multi Value Logic | ||
|
||
While you are able to filter based on an arbitrary number of fields, you are also able to | ||
pass multiple values for the same field. In most cases filtering on multiple values is | ||
implemented as a logical OR operation. A notible exception is the `tag` filter which | ||
is a logical AND. Passing multiple values for one field, can be combined with other fields. | ||
|
||
For example, filtering for devices with either the name of DC-SPINE-1 _or_ DC-LEAF-4: | ||
``` | ||
/api/dcim/devices/?name=DC-SPINE-1&name=DC-LEAF-4 | ||
``` | ||
|
||
Filtering for devices with tag `router` and `customer-a` will return only devices with | ||
_both_ of those tags applied: | ||
``` | ||
/api/dcim/devices/?tag=router&tag=customer-a | ||
``` | ||
|
||
## Lookup Expressions | ||
|
||
Certain model fields also support filtering using additonal lookup expressions. This allows | ||
for negation and other context specific filtering. | ||
|
||
These lookup expressions can be applied by adding a suffix to the desired field's name. | ||
E.g. `mac_address__n`. In this case, the filter expression is for negation and it is seperated | ||
by two underscores. Below are the lookup expressions that are supported across different field | ||
types. | ||
|
||
### Numeric Fields | ||
|
||
Numeric based fields (ASN, VLAN ID, etc) support these lookup expressions: | ||
|
||
- `n` - not equal (negation) | ||
- `lt` - less than | ||
- `lte` - less than or equal | ||
- `gt` - greater than | ||
- `gte` - greater than or equal | ||
|
||
### String Fields | ||
|
||
String based (char) fields (Name, Address, etc) support these lookup expressions: | ||
|
||
- `n` - not equal (negation) | ||
- `ic` - case insensitive contains | ||
- `nic` - negated case insensitive contains | ||
- `isw` - case insensitive starts with | ||
- `nisw` - negated case insensitive starts with | ||
- `iew` - case insensitive ends with | ||
- `niew` - negated case insensitive ends with | ||
- `ie` - case sensitive exact match | ||
- `nie` - negated case sensitive exact match | ||
|
||
### Foreign Keys & Other Fields | ||
|
||
Certain other fields, namely foreign key relationships support just the negation | ||
expression: `n`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.