5 years ago
API Filtering
Is it possible to apply multiple filters to an API query? If so, would anyone have an example of what it would look like?
Here are my current attempts:
Working:
https://...
As far as i can tell, even in the examples, these filters aren't looking for a single property with the name and value. it's looking a device having a property with name sn.sys_class_name and also having a property with value cmdb_ci_hardware. However, i don't think there's anything in the filter logic that actually pairs the two up, looking only for a property with name sn.sys_class_name also having the value cmdb_ci_hardware. Also, looks like the criteria also has to be in quotes. Not sure if this is exactly how it works under the hood, but this is how I understand it: the api looks at the JSON and evaluates it against the filter. There's an object in the JSON for each returned device called "customProperties". That object is a list, so it contains objects, each of which has a name and a value. It would appear that if you specify a dot in the field name (i.e. customProperties.name) the filter uses an "in" operator to see if your criteria (sn.sys_class_name) is in the list somewhere. In this case, it's looking to see if there's a property with name = "sn.sys_class_name" anywhere in the customProperties object. It would appear to repeat this process for the value.
That said, I personally don't do much filtering in my API call beyond a single criterion. My API calls are already being called from a script which gives me the opportunity to do post request-response processing, so I tend to pull down more than I usually need and do further filtering in the script. Not making excuses, just offering how I work around the issue.