@rcsr
I guess I have to use it, but I’m not exited about it.
For one, now I will have to migrate twice, once to the v1 CQL search and then a second time to the v2 version, whether that will be a CQL search or something similar.
Also the CQL search is slower (129ms to 295ms) compared to my old search (83ms to 108ms).
How do you search for a page with this title: A “test” page
When trying /wiki/rest/api/content/search?cql=title="A "test" page"
I get com.atlassian.confluence.api.service.exceptions.BadRequestException: Unrecognised clause at : test" page"
When trying /wiki/rest/api/content/search?cql=title="A \"test\" page"
I get a 400 error directly from the Apache Tomcat
When trying /wiki/rest/api/content/search?cql=title=%22A %5C%22test%5C%22 page%22
I get com.atlassian.confluence.api.service.exceptions.SSStatusCodeException: CQL was parsed but the search manager was unable to execute the search. Error message: com.atlassian.confluence.api.service.exceptions.SSStatusCodeException: There was an illegal request passed to XP-Search Aggregator API : HTTP/1.1 400 Bad Request
@t.bundt
Yes I think this is an outstanding bug. One workaround you could do is to first sanitize the query using a regex to remove all the special characters and use the CONTAINS operator instead of the EQUALS operator like so:
const title = `A "test" page`.replace(/[^a-zA-Z0-9 ]/g, "");
// A test page
const res = await AP.request(`/rest/api/content/search?cql=title~"${title}"`);
console.log(JSON.parse(res.body));
The above query worked for me when I tested it and should hopefully get you close enough to the desired page.
For other special characters like [ ] you can sanitize them using encodeURIComponent
e.g. A [test] page becomes wiki/rest/api/content/search?cql=title="A%20%5Btest%5D%20page" and returns back the expected page even when using the EQUALS operator.
This doesn’t work for double quotes though, unfortunately, so it doesn’t solve your initial problem with A "test" page.
Seeing as the bug may never be fixed, I would do some defensive programming in the meantime to handle these special characters. The full list of special characters can be found here.
This is actually something that is around the corner - we are targeting a release in early July that would include support for this. However, the changes recently made it to prod
Could you try the above again and see if it works for you?