string filters in the API (groovy)
In the past I have not had much need of filters in API, and on the rare occasion I have, it has been numeric filters. But for some reason I cannot get string filters to work at all without throwing errors, either 400 responses, or else unexpected character errors.
I can do this all day and get results:
queryParams = '?offset=' + offset.toString() + '&size=1000&filter=id:1256';
But as soon as I try to make my filter a string filter, I get errors, and I’ve seen both of the following used in various LM docs online, as if they would work, but I just get unexpected string errors:
queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:active';
queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:”active”';
Basically, I’m pretty sure I’m just not passing in the string value I want for status in a correct way. I’ve literally seen LM documentation of status:active and I’ve seen other examples when they do name~”whatever” but both of these throw errors. I can even test for status being a number (which obviously give no results), and with no filter, I get back everything (I’m doing setting/admins).
And I’ve tried every permutation of quotes in double quotes or backslashed quotes or double and triple quotes and double quotes. Because it something NEWBIE-ish I’m doing wrong.
When building a url for the API in groovy, is there some specific way to quote up a string value on a filter?
//build the request URL
resourcePath = "/setting/admins";
//queryParams = "?size=1000&offset=" + offset.toString();
//queryParams = '?offset=' + offset.toString() + '&size=1000&filter=id:1256';
//queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:1256';
queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:active';
queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:”active”';
url = "https://" + account +".logicmonitor.com/santaba/rest" + resourcePath + queryParams;
The first 3 commented items work fine (tho the 3rd one has no results obviously because 1256 isnt a valid status) but as soon as I try status:active or status:”active” its game over.
What newbie thing am I doing wrong?
Thanks in advance. Cheers!
You need to url encode the quotes if they aren’t already. So when you send it, it needs to look like this.
/setting/admins?filter=status%3A%22active%22
Things like Postman auto do that for you.