Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do you limit a search by label to a space in the RESTful API?

Christopher Haccius
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 26, 2019

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 (&#126; - so <my_space> = &#126;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?

 

4 answers

1 accepted

1 vote
Answer accepted
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2019

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

 

Christopher Haccius
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 26, 2019

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.

Like Stan Ry likes this
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2019

Hi @Christopher Haccius

Glad to hear it helped! Cheers, Stan.

0 votes
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2019

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
0 votes
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2019

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.

0 votes
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2019

Hi @Christopher Haccius,

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events