Confluence REST搜索API无法解析CQL。

huangapple go评论46阅读模式
英文:

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~&quot;Agent+Alert+-+SYS_THRESHOLD_REACHED&quot; and label=&quot;agent-event&quot;`

<details>
<summary>英文:</summary>

Managed to work it out...

1. it doesn&#39;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~&quot;Agent+Alert+-+SYS_THRESHOLD_REACHED&quot; and label=&quot;agent-event&quot;`

</details>



huangapple
  • 本文由 发表于 2023年2月8日 09:41:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定