Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Spaces are causing CQL query to fail

Foti Mougos
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 30, 2018

I'm trying to use a cql query in an Ajax GET to get some search suggestions. So far it works for a single word (like below), and returns 5 suggestions as intended.

http://<myurl.com.au>/rest/api/content/search?cql=text~wifi&limit=5&type=page

However any spaces I add to the search end up double encoding the spaces as %2520 and cause the query to fail with the following error:

http://<myurl.com.au>/rest/api/content/search?cql=text~wifi%2520network&limit=5&type=page

"message":"Could not parse cql : text~wifi%20network"}

Is my syntax for the request wrong? How can I handle spaces/multiple words better? I'd be happy to share more of my code if its relevant.

1 answer

0 votes
Moses Thomas
Community Champion
December 31, 2018

@Foti MougosYou should try like this

http://<myurl.com.au>/rest/api/content/search?cql=text~"wifi  network"&limit=5&type=page

I think  you  are missing  the quotation mark  double quotation mark  "  "

see here also  for  some other example https://developer.atlassian.com/server/confluence/performing-text-searches-using-cql/

 

best regards,

Foti Mougos
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 1, 2019

Hi Moses,

Thanks for the reply, unfortunately this didn't work:

https://<myurl.com.au>/rest/api/content/search?cql=text~%2522wifi%2522&limit=5&type=page

 

Unfortunately the quotations are still getting double encoded as %2522 when they reach the server.

My javascript that builds the URL and passes it to the Ajax is below, I've tried both using quotes explicitly and using the encoded %22.

var searchURL = 'http://myurl.com.au/rest/api/content/search?cql=text~%22' + text + '%22&limit=' + limit + "&type=page";

OR

var searchURL = 'http://myurl.com.au/rest/api/content/search?cql=text~"' + text + '"&limit=' + limit + "&type=page";

 

If I copy paste the URL with %22 I don't get any errors. I'm just not sure what is double encoding the quotation marks or spaces in my request. Do you have any other ideas?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events