英文:
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.
<details>
<summary>英文:</summary>
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.
</details>
# 答案1
**得分**: 0
成功解决了...
1. API 中似乎不支持 `contains`,所以必须使用 `~`
2. 在标题搜索中,空格需要替换为 `+`
所以最终接受的表达是
`title~"Agent+Alert+-+SYS_THRESHOLD_REACHED" and label="agent-event"`
<details>
<summary>英文:</summary>
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"`
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论