Hello,
I’m attempting to obtain the output via JSON for this query:
I have this stored as ‘rel.txt’ -
(name of it | "n/a", ids of it, hostname of it, value of result from (bes property "Local Time Zone - Unix") of it | "n/a") of bes computers whose (exists value of result from (bes property "Local Time Zone - Unix") of it)
Very close. I really dislike using ‘curl’ for REST API, normally I’d suggest using Python or PowerShell or anything else really, but it looks like you’re already putting a lot of best-practice into this (like putting the query in an external file and letting curl url-encode it for you), so congratulations.
One of the main issues is in how GET differs from POST. When we GET, all the parameters (the relevance=some_query, output=json) have to be URL-encoded and put into the URL.
When we POST, it behaves like HTML form data - the client sends one or more key/value pairs to the server, encoded as form data. When you give Curl the parameter “relevance@rel.txt”, what you’re saying is that for the POST data the “relevance” key will be provided by the rel.txt file, and Curl submits it as “relevance=‘whatever is in the file’”
There are probably a couple of different ways to handle this in curl.
The method which which I’m more familar is to add another ‘-d’ parameter, so “output=json” is sent as another value in the form POST:
> type query.txt
now
curl -k -u %BESUSER%:%BESPWD% -X POST -d "output=json" --data-urlencode "relevance@query.txt" https://bes-root.l
ocal:52311/api/query
{"result":["Wed, 30 Oct 2024 07:30:12 -0500"],"plural":false,"type":"time","evaltime_ms":0}