0

I am using both Postman and Javascript to query the Confluence API on a Cloud atlassian.net account.

When I use + in places of the spaces for CQL it works for me (so this isn't a matter of working out authorization - this works!!):

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

However using spaces does not:

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

Nor does the encoded version:

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

They both result in:

{
  "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"
}

Based on the documentation I see no mention of needing to use the + I was only able to gleen this based on the discussion following a question on Atlassian Answers.

The pluses are fine, but I need to use the fuzzy search to search multiple terms so things like:

title+~+deploy+my+app

Will result in:

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

and:

title+~+"deploy+my+app"

Will result in:

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

Is there a way to search a multi-word string for this cloud application?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
aaron blythe
  • 324
  • 1
  • 7

1 Answers1

0

Yes I have experienced this too and its quite infuriating. It doesn't seem to be encoding properly.

My workaround was to write my own urlencode function. If there is a better way to do this, I would love to hear it:

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
}

call it like this:

urlencode "${JIRA_FILTER_TEXT}"
Somaiah Kumbera
  • 7,063
  • 4
  • 43
  • 44