confluence-rest-api

Confluence REST search API could not parse cql


In [50]: r = confluence.search(cql=f'title contains "Agent Alert - {event_name}" and label = "agent-event"')

# prints the params of the request
{'cql': 'title contains "Agent Alert - SYS_THRESHOLD_REACHED" and label = "agent-event"', 'expend': 'body.view'}

And I get this error

In [49]: r.content
Out[49]: b'{"statusCode":400,"data":{"authorized":false,"valid":true,"allowedInReadOnlyMode":true,"errors":[],"successful":false},"message":"Could not parse cql : title contains \\"Agent Alert - SYS_THRESHOLD_REACHED\\" and label = \\"agent-event\\"","reason":"Bad Request"}'

However I tried using the exact string in confluence webUI and it works.


Solution

  • Managed to work it out...

    1. it doesn't seem to like contains in the API, so have to use ~
    2. the spaces need to be replaced with + within the title search

    so turned out this is what is accepted

    title~"Agent+Alert+-+SYS_THRESHOLD_REACHED" and label="agent-event"