Atlassian Confluence REST CQL endpoint failing intermittently - how can we get this fixed?
Asked by Anurag Gulati:

See the logs.

The query is EXACTLY the same but it fails the second time.

Can anyone explain why?

How do I get this fixed?

09/10/2020 04:41:56 AM Coordinated Universal Time \*\*\*\*\*\*STARTING\*\*\*\*\*\*  
09/10/2020 04:41:56 AM Coordinated Universal Time check time is (workaround - conf rest api will -1 hour)2020/09/10 05:41  
09/10/2020 04:41:56 AM Coordinated Universal Time New Page Check query is: type=page and space in ('SIS') and created \>= "2020/09/10 05:41"  
09/10/2020 04:41:57 AM Coordinated Universal Time Modified Page Check query is: type=page and space in ('SIS') and lastmodified \>= "2020/09/10 05:41" and created\<"2020/09/10 05:41"  
09/10/2020 04:41:57 AM Coordinated Universal Time Processing pages created after check time  
09/10/2020 04:41:57 AM Coordinated Universal Time Processing pages created before check time but modified since  
09/10/2020 04:41:57 AM Coordinated Universal Time \[\]  
09/10/2020 04:41:57 AM Coordinated Universal Time parse_confluence took 0.437488317489624 seconds to execute  
09/10/2020 04:42:12 AM Coordinated Universal Time \*\*\*\*\*\*STARTING\*\*\*\*\*\*  
09/10/2020 04:42:12 AM Coordinated Universal Time check time is (workaround - conf rest api will -1 hour)2020/09/10 05:41  
09/10/2020 04:42:12 AM Coordinated Universal Time New Page Check query is: type=page and space in ('SIS') and created \>= "2020/09/10 05:41"  
09/10/2020 04:42:12 AM Coordinated Universal Time Confluence Server Error  
09/10/2020 04:42:12 AM Coordinated Universal Time message  
Traceback (most recent call last):  
File "C:\\Python\\Python38\\lib\\site-packages\\atlassian\\confluence.py", line 1589, in cql  
response = self.get('rest/api/search', params=params)  
File "C:\\Python\\Python38\\lib\\site-packages\\atlassian\\rest_client.py", line 176, in get  
response = self.request('GET', path=path, flags=flags, params=params, data=data, headers=headers,  
File "C:\\Python\\Python38\\lib\\site-packages\\atlassian\\rest_client.py", line 161, in request  
response.raise_for_status()  
File "C:\\Python\\Python38\\lib\\site-packages\\requests\\models.py", line 941, in raise_for_status  
raise HTTPError(http_error_msg, response=self)  
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: [https://srb-integration-showcase.atlassian.net/wiki/rest/api/search?start=0\&limit=1000\&cql=type%3Dpage+and+space+in+%28%27SIS%27%29+and+created+%3E%3D+%222020%2F09%2F10+05%3A41%22](https://srb-integration-showcase.atlassian.net/wiki/rest/api/search?start=0&limit=1000&cql=type%3Dpage+and+space+in+%28%27SIS%27%29+and+created+%3E%3D+%222020%2F09%2F10+05%3A41%22)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  
File "C:\\Code\\Integrations\\int\\scripts\\integrations\\parse_confluence.py", line 62, in parse_confluence  
new_pages=confluence.cql(cql_created_after_check, start=0, limit=1000)  
File "C:\\Python\\Python38\\lib\\site-packages\\atlassian\\confluence.py", line 1592, in cql  
raise ApiValueError("The query cannot be parsed", reason=e)  
atlassian.errors.ApiValueError: The query cannot be parsed


Answers:
author: sam saas
body: Hi [@Anurag Gulati](/t5/user/viewprofilepage/user-id/4033503) ,  

Please refer this : <https://community.atlassian.com/t5/Confluence-questions/Search-content-API-fails-with-CQL-error-for-cql-lastModified-gt/qaq-p/1552066#U1553018>

Hope this helps !


author: Dario B
body: Hello [@Anurag Gulati](/t5/user/viewprofilepage/user-id/4033503) ,

Welcome to the Atlassian Community!

If I understand correctly you are calling twice (or more times) the same REST API endpoint with the same parameters in your code and while everything works fine the first time, at the successive attempt you get answer 400 (bad request) with error message "The query cannot be parsed". Is this correct?

If this is correct, can you kindly let us know:

1. How long is your code waiting before running the second call?
2. Is the CQL query always the same?
3. When is the last time this failed (so I can go check the logs)?
4. Can you reproduce the issue using [Curl](https://curl.haxx.se/)? E.g. by running the below command multiple times (replace : \<EMAIL\> and \<API_TOKEN\> with the email address and the [API Token](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) used to authenticate the request)  

   ```
   curl -D- -u <EMAIL>:<API_TOKEN> -X GET 'https://srb-integration-showcase.atlassian.net/wiki/rest/api/search?start=0&limit=1000&cql=type%3Dpage+and+space+in+%28%27SIS%27%29+and+created+%3E%3D+%222020%2F09%2F10+05%3A41%22'
   ```

Cheers,  
Dario


Tags: cloud

confluence-cloud