Extract Confluence page url on creation via scriptrunner in jira

Madhusudhan Matrubai April 1, 2016

I'm currently using this wonderful functionality in scriptrunner plugin. - https://scriptrunner.adaptavist.com/latest/jira/interacting-with-confluence-from-jira.html

wherein part of my release process in jira, I'm creating confluence page for release notes.

Would like to know if it's possible to return the url on creation so that I can update in one of my "Release Notes" custom field. 

Thanks

2 answers

2 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 3, 2016

Thanos's answer should normally be sufficient, except if you have apostrophes or something in the URL.

The request returns the created page ID and link, you can get it using something like:

new groovy.json.JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]

That gives you the part of the link after the base url... the base url is also in there, but you know it already.

I don't know whether that stuff is intended for public consumption, so you could just get the page ID (key is "id" at the top level) and use /pages/viewpage.action?pageId=131077.

Deleted user May 4, 2018

Hi Jamie,

that works, but how do I retrieve the pageId only? I have to build the globalId with appId & pageId to populate the linkbuilder?

e.g.

def globalId = 'appId=350eeaaa-0de6-36d0-bc1d-95761684b830&pageId=275829'    

linkBuilder.globalId(globalId)

Thank you!

Best regards,

Alex 

0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 2016

Hi Madhusudhan,

Yes you can store in a variable the link to the newly created confluence page because you know all the variables to just 'construct' the link, so...

def confluenceLink
authenticatedRequestFactory
    .createRequest(Request.MethodType.POST, "rest/api/content")
    .addHeader("Content-Type", "application/json"
    .setRequestBody(new JsonBuilder(params).toString())
    .execute(new ResponseHandler<Response>() {
    @Override
    void handle(Response response) throws ResponseException {
        if(response.statusCode != HttpURLConnection.HTTP_OK) {
            throw new Exception(response.getResponseBodyAsString())
        } else {
			confluencePageUrl = "<a href='${confluenceLink.displayUrl.toString()}/display/${spaceKey}/${pageTitle}'>${pageTitle}</a>"
		}
    }
})
 
return confluenceLink

Please let me know if this does the trick

 Regards

Suggest an answer

Log in or Sign up to answer