Confluence REST API搜索 - 编码时编码CQL查询时出错

问题描述 投票:0回答:1

我使用Postman和Javascript来查询Cloud atlassian.net帐户上的Confluence API。

当我在CQL空间的地方使用+时,它适用于我(所以这不是一个制定授权的问题 - 这可行!!):

https://mycompany.atlassian.net:443/confluence/rest/api/content/search?os_authType=basic&cql=type=page+and+space+in+(DEV,OPS)+and+title+~+deploy

但是,使用空格不会:

https://mycompany.atlassian.net:443/confluence/rest/api/content/search?os_authType=basic&cql=type=page and space in (DEV,OPS) and title ~ deploy

编码版本也不是:

https://mycompany.atlassian.net:443/confluence/rest/api/content/search?os_authType=basic&cql=type=page%20and%20space%20in%20(DEV,OPS)%20and%20title%20~%20deploy

他们都导致:

{
  "statusCode": 400,
  "data": {
    "authorized": false,
    "valid": true,
    "errors": [],
    "successful": false
  },
  "message": "Could not parse cql : type=page%20and%20space%20in(DEV,OPS)%20and%20title~deploy"
}

基于documentation我没有提到需要使用+我只能根据question on Atlassian Answers之后的讨论来收集这个。

这些优点很好,但我需要使用模糊搜索来搜索多个术语,例如:

title+~+deploy+my+app

将导致:

"message": "Could not parse cql : type=page%20and%20space%20in(DEV,OPS)%20and%20title~deploy my app"

和:

title+~+"deploy+my+app"

将导致:

"message": "Could not parse cql : type=page%20and%20space%20in(DEV,OPS)%20and%20title~%22deploy my app%22"

有没有办法为这个云应用程序搜索多字符串?

rest confluence confluence-rest-api
1个回答
0
投票

是的,我也经历过这一点并且非常令人生气。它似乎没有正确编码。

我的解决方法是编写自己的urlencode函数。如果有更好的方法,我很乐意听到它:

function urlencode() {
    local convert=$(convertFromAscii "$1")
    echo ${convert} | sed "s/'/%27/g" | sed "s/\\\/%5C/g"
}

function convertFromAscii() {
    local input=$1
    local length="${#input}"
    for (( i = 0; i < length; i++ )); do
        local c="${input:i:1}"
        case ${c} in
            [a-zA-Z0-9.~_-+\']) printf "$c" ;;
            '-') printf "-" ;;
            ' ') printf "%%20" ;;
            '!') printf "%%21" ;;
            '"') printf "%%22" ;;
            '#') printf "%%23" ;;
            '$') printf "%%24" ;;
            '%') printf "%%25" ;;
            '&') printf "%%26" ;;
            '(') printf "%%28" ;;
            ')') printf "%%29" ;;
            '*') printf "%%2A" ;;
            '+') printf "%%2B" ;;
            ',') printf "%%2C" ;;
            '<') printf "%%3C" ;;
            '=') printf "%%3D" ;;
            '>') printf "%%3E" ;;
            '?') printf "%%3F" ;;
            '[') printf "%%5B" ;;
            ']') printf "%%5D" ;;
        esac
    done
}

这样叫:

urlencode "${JIRA_FILTER_TEXT}"
© www.soinside.com 2019 - 2024. All rights reserved.