jgstew
June 30, 2015, 3:02am
1
I can’t seem to return a string using session relevance through the REST API that contains:
"
Like:
this="that"
How do I do this?
in /webreports?page=QNA I can do the following:
Q: "%22"
A: "
With the REST API: (using cURL GET) …/api/query?relevance=%22%22%22
Q: "%22"
E: ERROR
Q: %22%22%22
E: ERROR
Q: "%22that%22"
A: that
1 Like
jgstew
June 30, 2015, 4:56pm
2
This seems to be the answer:
waithidden curl -k --data-urlencode relevance="%22this=%2522that%2522%22" -o "{pathname of folder "__Download" of client folder of current site}\BaselineComponents.xml" --user {parameter "currentConsoleUser"}:{parameter "secret"} https://{parameter "RootServerURL"}/api/query
The trick was to escape the % in the %22 so having a literal quote requires: %2522 to “double escape” the quote. Also, I’m not sure what extra escaping –data-urlencode is doing as well.
2 Likes
For reference… I was looking through how we did this with our REST API implementation.
We use the Rest API C# library the bigfix team published: https://bitbucket.org/bigfixme/bigfix-rest-api-c-library
When you call GetRest() you only then need to escape the quotes the same way you would normally escape quotes in C#… e.x. “computers whose (name of it contains “NYEAST”)”
1 Like
jgstew
June 30, 2015, 9:30pm
4
Your example would not put quotes in the string itself, but it seems like %22 would directly in the case of C#
In the case of cURL the way I am using it, you need to do %22 for normal quotes and %2522 for quotes in the string itself.
1 Like
You’re right – my bad. I guess we haven’t had to use quotes directly in session relevance yet.
2 Likes
jgstew
Split this topic
January 22, 2016, 5:26pm
6
Because of the decoding happening in multiple steps, you need to percent encode the percent to get around this.
session relevance
"%22"
rest query
https://brollytest:52311/api/query?relevance=(%22%252522%22)
on the first decode pass,
the outer %22
turns into "
the outer %25
turns into %
Then on the second decode pass you effectively have "%2522"
which converts to a "%22"
and finally to a """
1 Like
I find it easier to POST a query via curl or script. We keep the query in a separate text file and let the application do the encoding for us.
Just a bit more to round this out…
When I sent a more complex query, I got an error message “String did not contain a closing quotation mark”. I believe that’s because curl was handling the pipe operator “|” as a shell command. My workaround is to change the query file to take ‘relevance=’ off the front and pass that explicitly to curl
curl --insecure --user username --data-urlencode "output=json" -X POST "https://bes-root-server:52311/api/query" --data-urlencode "relevance@query.txt"
Conte…
1 Like