How to pass contentStatuses in cqlContext object for CQL Search API?
Can you share a sample request for getting items with status = current?
Hey @JatinChopra / @raz Can you guys answer this question of mine too?
Looking at the Search endpoint on the Developer Documentation https://developer.atlassian.com/cloud/confluence/rest/api-group-search/#api-group-search
It looks as though you need to pass a cqlcontext query parameter to the endpoint as an object.
https://your-domain.atlassian.net/wiki/rest/api/search?cql=type=page&cqlcontext=%7B%22contentStatuses%22%3A%5B%22current%22%5D%7D
I found that I needed to URLEncode the entire object but this is what it looks like without the encoding:
{"contentStatuses":["current"]}
Content statuses is an array of statuses as you can pass multiple.
This doesn’t seem to work for me. I am passing spaceKey and have a different space in CQL clause. I expect the API to give no response.
Is this specific to Confluence version?
It works great for contentStatuses, however, it does not respond as intended for spaceKey and contentID. Can you please assist me regarding this issue
I did some tests based on https://developer.atlassian.com/server/confluence/cql-function-reference/#current-space and confirmed that:
Param cqlContext with spaceKey only works when using function currentSpace() as part of your cql param.
For example:
/wiki/rest/api/content/search?cql=type=page AND space=currentSpace()&cqlcontext=
{“contentStatuses”:[“draft”],“spaceKey”:“TST”}
And, of course, all the cqlContext needs to be URL encoded to avoid issues.
Thanks for the help! This solved the problem where the API wouldn’t obey the spaceKey.
You are a life saver! My only question: is currentSpace()
safe to use on Confluence Cloud?
It doesn’t seem to be documented on the equivalent page for cloud: https://developer.atlassian.com/cloud/confluence/cql-functions/.
It seems to do the trick, but being undocumented (on Cloud) I’m afraid it may break unexpectedly.
You make a good point. I agree it’s risky to use undocumented features. So let’s assert it’s a documentation bug on the grounds that it’s undocumented. Would you mind opening this as a bug with developer support?
Good shout! I opened a ticket (ECOHELP-44348) earlier this week, enquiring whether currentSpace()
was OK to use despite being undocumented. I received a response this morning:
The dev team has confirmed that it is safe to use CQL function
currentSpace()
in Confluence cloud as well. I have asked the team to get this function officially documented.
I’ll keep an eye on https://developer.atlassian.com/cloud/confluence/cql-functions/, hopefully it pops up there some time in the future.
I’m using /search endpoint to get latest changes in confluence. And I want to include not only current status, but also archived and deleted/trashed. But when I pass them to the contentStatus
object, only “archived” seem to work.
For example, query:
/wiki/rest/api/content/search?cql=type=page&expand=ancestors&limit=100&cqlcontext=%7B"contentStatuses"%3A%5B"trashed"%5D%7D
Outputs:
While query:
/wiki/rest/api/content/search?cql=type=page&expand=ancestors&limit=100&cqlcontext=%7B"contentStatuses"%3A%5B"archived"%5D%7D
Works correctly (unfortunately I can attach only media file, but response contains objects only with status: “archived”)
The only way I see for now is to get all deleted/trashed pages with query:
/wiki/api/v2/pages?status=trashed&limit=250
That works well.
Do you happen to know if there is a list of statuses that can be passed to contentStatuses
array?