Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Confluence Server REST API Search with ScriptRunner


I have a problem with searching pages in Confluence. I executing my request from Jira by scriptrunner:

private checkIfPageExist(String pageName, confluenceLink)
def status = false;
log.error "checkIfPageExist pageName: "+pageName

if(pageName.contains(" "))
pageName = pageName.replace(" ","%20")

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
.createRequest(Request.MethodType.GET, "/rest/api/content/search?cql=title=%22${pageName}%22")
.addHeader("Content-Type", "application/json")
.execute(new ResponseHandler<Response>() {
void handle(Response response) throws ResponseException {
if(response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.getResponseBodyAsString())
else {
log.error "response: "+response.getResponseBodyAsString()
def resp = new JsonSlurper().parseText(response.responseBodyAsString)
if(resp.results.title[0].toString().toLowerCase() == pageName.toLowerCase())
status = true;
catch(Exception ex)
log.error "Error: ${ex}"
return status


I have created page in Confluence with name "Test". In my problematic case this function trying to find page with name "test". Function returns false because search engine does not recognize the size of characters.
But another function in my code is resposible for creating page and creating fail because Confluence returns information that page with the same name exist.

How can I provide recognizing size of characters in searching via API in Confluence?

2 answers

I to am attempt to connect to Confluence Server from our Jira Server using this approach.

However, I am getting a 'nonce used' error when attempt to execute my confluence search.

The error stack is below. 

Per it appears we can no longer use this approach to execute calls against Confluence from Jira.  Is this known?  Would anyone happen to know a workaround if it even exists?  Obviously this approach is preferred versus having to make REST calls and hard code credentials or even an auth token into the script. And to head off the likely question I've tried with my application link set to both 'oauth' and 'oauth with impersonation', same results...

java.lang.Exception: oauth_problem=nonce_used at Script1150$1.handle(Script1150.groovy:42) at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle( at$1.handle( at$1.handle( at$2.handle( at at at at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute( at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle( at$1.handle( at$1.handle( at$2.handle( at at at at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute( at com.atlassian.applinks.oauth.auth.OAuthRequest.execute( at$execute$ Source) at Script1150.findConfluencePages(Script1150.groovy:38) at

0 votes

Hey, @Paweł Jakimiak ! So, I think the problem is caused because your are searching for titles using the EQUALS operator, which is case sensitive. If you want to do a case insensitive search, you should use the CONTAINS operator.

So, instead of


use a URL like


That will find pages regardless of case.

That said, your check on this line:

if(resp.results.title[0].toString().toLowerCase() == pageName.toLowerCase())

may need a little work if you use the CONTAINS (~) operator. That will only check that the first result in your search results matches your pageName variable. That may not be the case if you use the CONTAINS operator, since that will find more results. You might want something more like:

if (resp.results.any { it.toString().toLowerCase() == pageName.toLowerCase() })

to see if any of the pages returned have the same name, regardless of case, as using the CONTAINS operator is likely to yield many more results than EQUALS.

For more information, check out the Operators reference in the CQL docs.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

205 views 1 6
Read article

Atlassian Community Events