Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Cloud icon
Cloud

Perform a CQL Search in ScriptRunner for Confluence Cloud

Tags
Created 8 month(s) ago, Updated 27 day(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence
Language |
groovy
import com.atlassian.confluence.rest.clientv1.model.ContentArray

final def SPACE_KEY = "<YOUR_SPACE_KEY>"
final def CQL_QUERY = "type=page and space=${SPACE_KEY}" // Replace the value of CQL_QUERY with the CQL query of your choice

def searchResult = get("/wiki/rest/api/content/search")
        .queryString("cql", CQL_QUERY)
        .asObject(ContentArray).body

if (searchResult && searchResult.size > 0) {
    def nextUrl = searchResult._links.next
    def contents = searchResult.results

    while (nextUrl) {
        def nextContents = get("/wiki${nextUrl}").asObject(ContentArray).body
        nextUrl = nextContents._links.next
        contents += nextContents.results
    }

    contents.each { content ->
        logger.info "content title is ===> ${content.title}"
    }
} else {
    logger.warn("Can not find any result from the CQL_QUERY")
}
Having an issue with this script?
Report it here