Append text in API relevance query?

Short version: Ampersands break things in API relevance queries. How do you get around this for append operations?

Long version: In another topic, a relevance statement was suggested for use via /api/query?relevance=... that included ampersands as append operators. This ends up clipping the relevance off at the ampersand and throwing a “This expression could not be parsed” error. Several regulars suggested that the error was due to a syntax error, but the problem is actually the ampersand, which has special meaning in URLs, HTML, and XML, all of which are involved in using the API. Based on some Googling, I tried replacing the ampersands in the query with & (HTML) and & (XML) but they both still clip the query.

Is there actually a way to use append operators in a relevance statement to be passed to the REST API?

I just converted the following using https://www.urlencoder.org and got the correct results.

ids of bes computers whose ("|computer1|computer2|" as lowercase contains ("|" & name of it as lowercase & "|"))
ids%20of%20bes%20computers%20whose%20%28%22%7Ccomputer1%7Ccomputer2%7C%22%20as%20lowercase%20contains%20%28%22%7C%22%20%26%20name%20of%20it%20as%20lowercase%20%26%20%22%7C%22%29%29

Looks like the trick is percent encoding the ampersand as %26?

1 Like

Bother…I think I knew that one but it slipped my mind. Will give it a try. Thanks!

1 Like

See also
https://forum.bigfix.com/t/bes-properties-that-are-not-set-or-unkown-causing-relevance-query-issue/28061/10

Check that post, and the follow-ups after it, for another improvement on the method of using a data file with curl for the query, rather than putting it all on the command line

1 Like

Well, at the moment, I’m not actually using curl. Rather, I’m working on a PowerShell framework of sorts to streamline my use of the API in reporting and other scripts, so this is in a sense specifically for use on the command line. :slight_smile:

That post looks good, though. Will read very soon (and likely often). :smiley: