SOLVED: How do I get a DoubleQuote in a session relevance result using the rest api

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

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

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

2 posts were split to a new topic: Issues with escaping DoubleQuotes in session relevance with REST API

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.

1 Like