Exact search for prefix via API

21 views
Skip to first unread message

Dean Moore

unread,
Apr 8, 2019, 11:09:32 AM4/8/19
to NetBox
Afternoon,

I'm hitting a snag when using the API to find a prefix list where the filter is returning all prefix items containing the q term.

eg: 

code is the search term, it is a code identifying an asset, it is 3-6 uppercase a-z.
 
prefixe = nb.ipam.prefixes.filter(q=code, role='agn')

The issue Im having is it will return multiple prefixes that contain the filter, if I have 3 prefixes with a description ABC, ABCD, ABCDE and search for ABC I will receive all 3 as expected.

Would it be possible to either specify an exact match for the 'q' field or on the description field?

Other than updating over 500 entries with a tag is there some other way I can find the exact item?

Regards

Dean



Brian Candler

unread,
Apr 9, 2019, 3:18:40 AM4/9/19
to NetBox
q is a generic query like if you'd typed it in the web interface.  It queries a large number of different fields for substrings.

I haven't tested this myself, but have you tried filter(description="ABC") ?
Reply all
Reply to author
Forward
0 new messages