Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner failing to execute confluence query using applink from Jira

Hello,
Im attempting to connect to Confluence from Jira via applink leveraging the provided adaptivist solution at https://library.adaptavist.com/entity/create-a-confluence-page-for-each-subtask-of-an-issue but it is continually failing with a 'nonce_used' error when the cql call is executed.
I've compared the HTTP headers between Jira and confuence for the ouath calls and it all looks like it matches on both sides and at this point Im completely stuck.  I've also tried both applink config options of 'oauth' and 'oauth with impersonation' with the same failing result.


I really need to get this solutoin working since making rest calls using basic auth or an access token is a non-starter due to then needing to add the auth details in the script.

Can someone please help me to understand what may be going wrong here?

  • Jira Server: 8.5.3
  • Confluence Server: 7.5.2
  • Scriptrunner: 6.23

Code being executed from Scriptrunner console:

findConfluencePages()

static ApplicationLink createPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService)

final def conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class)
conflLink
}

int findConfluencePages() {


def confluenceLink = createPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()


def responseBody
authenticatedRequestFactory
.createRequest(Request.MethodType.GET, "cql=type%3Dpage%20and%20space%3DAE%20and%20label%3D%22rsp-unreleased%22&expand=body")
.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.responseBodyAsString)
} else {
responseBody = new JsonSlurper().parseText(response.responseBodyAsString)
}
}
})

responseBody["id"] as Integer
}



 

Failing stack:

java.lang.Exception: oauth_problem=nonce_used at Script1167$1.handle(Script1167.groovy:44) at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle(OAuthResponseHandler.java:48) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:115) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:113) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$2.handle(JerseyRequest.java:134) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:102) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.executeAndReturn(JerseyRequest.java:131) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.execute(JerseyRequest.java:113) at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute(ApplicationLinkRequestAdaptor.java:50) at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle(OAuthResponseHandler.java:46) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:115) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:113) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$2.handle(JerseyRequest.java:134) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:102) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.executeAndReturn(JerseyRequest.java:131) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.execute(JerseyRequest.java:113) at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute(ApplicationLinkRequestAdaptor.java:50) at com.atlassian.applinks.oauth.auth.OAuthRequest.execute(OAuthRequest.java:71) at com.atlassian.sal.api.net.Request$execute$0.call(Unknown Source) at Script1167.findConfluencePages(Script1167.groovy:40) at Script1167.run(Script1167.groovy:15)

1 answer

@Greg Bailey 

can you try method may it will help you

 

def authenticatedRequestFactory = confluenceLink.createAuthenticatedRequestFactory()

def req = authenticatedRequestFactory.createRequest(GET,"cql=type%3Dpage%20and%20space%3DAE%20and%20label%3D%22rsp-unreleased%22&expand=body")

def handler = new ApplicationLinkResponseHandler<Map>() {
@Override
Map credentialsRequired(Response response) throws ResponseException {
return null
}

@Override
Map handle(Response response) throws ResponseException {
assert response.statusCode == 200
new JsonSlurper().parseText(response.getResponseBodyAsString()) as Map
}
}

def sessionDetails = req.execute(handler)
log.warn("Making the request as: " + sessionDetails)
def json_str = JsonOutput.toJson(sessionDetails)
def jsonSlurper = new JsonSlurper()
def cfg = jsonSlurper.parseText(json_str)
assert cfg instanceof Map
def id = cfg.results['id']

return id

Suggest an answer

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

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

533 views 1 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you