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

Responding to Confluence Events in Jira

At a recent ScriptRunner Champion Hour, I talked about how to respond to events in Confluence to update Jira.

The path we demonstrated was to use a combination of an Event Listener in Confluence and REST Endpoint in Jira. The details of using the App Links API are detailed in our documentation for ScriptRunner for Confluence (and for ScriptRunner for Jira, if you need to go the other direction). Here is the code I used.

The basic idea is that if a page in Confluence has a Jira Issue macro in it, then when someone likes that page, they should also automatically vote for the corresponding issue in Jira. Complexities like handling multiple issue macros or doing completely different operations in Jira & Confluence are left as exercises to the reader. :)

Set up a listener in ScriptRunner for Confluence

import com.atlassian.applinks.api.ApplicationLinkResponseHandler
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.sal.api.component.ComponentLocator
import groovy.json.JsonSlurper

LikeEvent event = event
def content = event.content

def xmlStorageFormat = content.bodyAsString
def document = new XmlSlurper(false, false)
    .declareNamespace([ac: ""])

def macros = document.'ac:structured-macro'
def issueKey = macros.children().find { element ->
    element.'@ac:name' == "key"

log.debug "Found link to issue key ${issueKey} in page ${content.title}"

if (issueKey) {
    For more details on using the App Links API, see
    def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
    def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
    def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
    def request = applicationLinkRequestFactory.createRequest(

    def handler = new ApplicationLinkResponseHandler() {
        Map credentialsRequired(Response response) throws ResponseException {
            return null

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


Then a REST Endpoint in Jira:

import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript


CustomEndpointDelegate customEndpointDelegate

    httpMethod: 'PUT',
    groups: ['jira-software-users']
) { MultivaluedMap queryParams ->
    def voteManager = ComponentAccessor.voteManager
    def issueService = ComponentAccessor.issueService
    def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
    def issueKey = queryParams.getFirst('issueKey')?.toString()
    def issue = issueService.getIssue(loggedInUser, issueKey).getIssue()
    voteManager.addVote(loggedInUser, issue)

    return Response.ok("Successfully voted for issue ${issueKey}").build()




Log in or Sign up to comment
Community showcase
Published in Confluence Cloud

🏠 Say hello to the new Confluence Home!

Hi Atlassian Community, My name is DJ Chung, and I’m a Product Manager on the Confluence Cloud team. Today, I’m excited to share a new and improved version of Home. The new Home helps you ...

43,432 views 32 135
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