I am using the Confluence RESTful API to retrieve all pages with a certain label from Confluence (where <my_label> is substituted with the label I am looking for):
/rest/api/content/search?cql=label=<my_label>&limit=500
Now I would like to constrain the search to pages contained in a specific space (<my_space> is the key of the space I am looking for), and I use the following request:
/rest/api/content/search?cql=label=<my_label>%AND%space=<my_space>&limit=500
This works great for space keys composed of only letters, e.g. <my_space> = ABCDE.
However, our private user spaces are composed of a tilde and letters, e.g. <my_space> = ~abcde, in which case I retrieve the REST reply:
{"statusCode":400,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"Expecting a value for operator '=' after field 'space' but got '~'"}
I've already tried to substitute the tilde by its HTML representation (~ - so <my_space> = ~abcde), but the REST reply remains the same.
Does anyone know how I can restrict the search by label to a certain space with a REST request which works for arbitrary space keys?
Trying to narrow the request to pages labeled with "content" label also worked fine.
The only difference I am seeing here between that request of yours and mine are quotes. I am taking the user name in double quotes, hence the %22 byte.
This request demonstrates searching for pages labeled with "content" label in the private space for user ~1234567890
GET https://example.net/<confluence_instance>/rest/api/search?cql=space%3D%22~1234567890%22%20and%20label%3Dcontent (200)
x-tcp-rtt: 12345
date: Tue, 26 Mar 2019 09:47:07 GMT
x-content-type-options: nosniff
server: nginx/1.15.7
x-seraph-loginreason: OK
x-frame-options: ALLOW
content-type: application/json
x-request-id: 123nasd98127u21usjasjsad7
cache-control: no-cache, must-revalidate
x-confluence-cluster-node-name: oasjweaajk
connection: keep-alive
transfer-encoding: chunked
x-confluence-cluster-node: 129jsadjao
x-ausername: 1234567890
expires: Thu, 01 Jan 1970 00:00:00 GMT
Hi @Stan Ry
thanks for your quick and valuable replies! All of your answers work perfectly well - I've selected this last one as the accepted answer since it is the exact answer to the question posed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear it helped! Cheers, Stan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just tried this and it worked fine:
GET https://example.net/<confluence_instance>/rest/api/search?cql=space%3D%22~1234567890%22 (200)
x-tcp-rtt: 38524
date: Tue, 26 Mar 2019 09:43:16 GMT
x-content-type-options: nosniff
server: nginx/1.15.7
x-seraph-loginreason: OK
x-frame-options: ALLOW
content-type: application/json
x-request-id: 4sdfsfsdfsdfdsfsdfd
cache-control: no-cache, must-revalidate
x-confluence-cluster-node-name: aaaa
connection: keep-alive
transfer-encoding: chunked
x-confluence-cluster-node: bbbb
x-ausername: 1234567890
expires: Thu, 01 Jan 1970 00:00:00 GMT
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So if you are doing like:
curl -k -S -v -u username -X POST -H "Accept: application/json" -H "Content-Type: application:sjon" -d @json.txt https://example.net/<confluence_instance_name>/rest/api/content/<page_ID>/label
your JSON in json.txt MUST be ASCII-encoded.
Example JSON in json.txt:
[{"prefix":"global", "name":"label_name"}]
I understand that's not exactly what you are looking for, but it is maybe this will give your some futher clue on error 400.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AFAIK error 400 means encoding issue. As far as I remember, REST awaits ASCII-encoded requests. I've also had issues submitting 8-bit lables through CURL. Result was all label's symbols substituted with question marks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.