Help with another Rest API Relevance query

Why does a POST to /api/query of
output=json&relevance=(names of it of properties of it, values of it) of property results of bes computers
and
output=xml&relevance=(names of it of properties of it, values of it) of property results of bes compters
return not easily parsable JSON and XML respectively. We a processing the result with a third party application which seems to need good JSON/XML.

For example, the result returned with the
/api/computer/[id]
query works just fine.

Can you name the 3rd party application or what it is written in?

There is a python library for interacting with the BigFix REST API.

These style queries are returned using platform APIs that are limited in what they can do, but are well formatted and should be used for what they are capable of.

This is session relevance and can return any arbitrary data you want, so it is not well formatted by default. This is just the nature of the fact that it returns data in any possible format. You can however write session relevance that returns the data in JSON format by writing in that way.

Example, this is how you could write a session relevance query that works for a single computer but returns JSON:

("{ " & it & " }") of concatenation ", " of ("%22" & name of properties of it & "%22: " & ("[ %22" & it & "%22 ]") of concatenation "%22, %22" of values of it) of property results of bes computers 00123400

And you could get the list of computer IDs to query using:

ids of bes computers whose(now - last report time of it < 45 * day)

Then this should be everything for all computers that have reported within the last 45 days:

("[" & it & "]") of concatenation ", " of ( ("{" & it & "}") of concatenation (", ") of (  ("%22name%22: %22" & it & "%22") of (name of it | "UnknownName"); ("%22id%22: " & it as string) of (id of it | 0); ("%22properties%22: { " & it & " }") of concatenation ", " of ("%22" & name of properties of it & "%22: " & ("[ %22" & it & "%22 ]") of concatenation "%22, %22" of values of it) of property results of it) ) of bes computers whose(now - last report time of it < 45 * day)

But this is reporting in a JSON schema that I made up, you could tweak it to be in whatever format you need, with some limitations.

That said, I would recommend getting a limited set of data of ALL computers, but then query all data from only certain computers.

Also, I am not escaping " (double quotes) within the property results, so this does NOT actually return valid JSON in cases where double quotes are within the property results, so more work is required, but there are some built in methods that might help with this.

Related:

2 Likes

Thanks. I will experiment with your suggestions.

1 Like

I finally got around to testing it. Too many projects going on at once :wink: .

Please forgive my ignorance, as I am fairly new to BF queries.

We are using PHP to make our requests and using POST to query the server. Our normal POST, which return a result which our 3rd part app fails to parse is the following:
$post = 'output=json&relevance=(names of it of properties of it, values of it) of property results of (bes computers whose (id of it equals ’ . $computerID . ‘))’;
We tried your suggestion using the following:
$post= ‘output=json&relevance=("[" & it & “]”) of concatenation “, " of ( (”{" & it & “}”) of concatenation (", “) of ( (”%22name%22: %22" & it & “%22”) of (name of it | “UnknownName”); ("%22id%22: " & it as string) of (id of it | 0); ("%22properties%22: { " & it & " }") of concatenation “, " of (”%22" & name of properties of it & “%22: " & (”[ %22" & it & “%22 ]”) of concatenation “%22, %22” of values of it) of property results of it) ) of bes computers whose(now - last report time of it < 45 * day)’;
We get the following:
{“result”:[],“error”:“This expression could not be parsed.”}
I am flummoxed.

You have a lot of “smart quotes” mixed with "straight quotes" there. Be sure your quotes are correct, and when posting back please use the code tag (</> above the editor window) so the code shows correctly as below:

("[" & it & "]") of concatenation ", " of ( ("{" & it & "}") of concatenation (", ") of ( ("%22name%22: %22" & it & "%22") of (name of it | "UnknownName"); ("%22id%22: " & it as string) of (id of it | 0); ("%22properties%22: { " & it & " }") of concatenation ", " of ("%22" & name of properties of it & "%22: " & ("[ %22" & it & "%22 ]") of concatenation "%22, %22" of values of it) of property results of it) ) of bes computers whose(now - last report time of it < 45 * day)

That query works in my Console Debugger, so if your quoting is not the problem, then your tool is not URL-encoding the query for you - some scripting languages will do that automatically, others won’t, and I’m not sure about PHP.

If you can post this as form data instead of part of the URL, that should work, is easier, and doesn’t require URL-encoding the relevance.