Forums

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

Confluence Server REST API Search with ScriptRunner

Paweł Jakimiak
Contributor
April 9, 2020

Hi,

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
try{

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

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
authenticatedRequestFactory
.createRequest(Request.MethodType.GET, "/rest/api/content/search?cql=title=%22${pageName}%22")
.addHeader("Content-Type", "application/json")
.execute(new ResponseHandler<Response>() {
@Override
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}"
}
finally
{
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?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events