Create Jira Tickets Based off of File List in Confluence
Asked by Rob:

I have Confluence and Jira Server linked together in application links. All of the normal integrations work just fine.

What I am looking for (might be wishing on a star here), is if there is an option/integration that would allow a user to drop a document in a File List in confluence and have that upload trigger a ticket getting created in Jira?

Or even if it was something like upload a file, click a button. And then a jira ticket would be created with a link to the newly uploaded file.

Any thoughts are welcomed!

Thanks!


Answers:
author: Hana Ku?erov?
body: Hi [@Rob](/t5/user/viewprofilepage/user-id/3659622) ,

I can imagine doing it using [ScriptRunner for Confluence](https://marketplace.atlassian.com/apps/1215215/scriptrunner-for-confluence?hosting=server&tab=overview). You can create custom script listener - there's AttachmentCreateEvent you can react on, but it will take some groovy programming.

Should the issue always be created to the specific project, or it will differ based on the space?

I've searched through marketplace and even though there are some applications, which enables you to create Jira issues easily, I didn't find any, which will do it based on the attachment.

comments: author: Rob
body: Thanks for the response Hana!

Yes, the issue would always be created in the same Jira project and triggered from the same space in Confluence.

I am not a programmer at heart. But I can sure delve in and see what I can find out. Maybe there are some snippets out on the web somewhere I can grab pieces of groovy to make it work.

Thank you!


author: Hana Ku?erov?
body: Hi [@Rob](/t5/user/viewprofilepage/user-id/3659622) ,

hopefully something like this will work for you - I just tested it and I was able to create the issue based on attachment creation. I got inspiration [here](https://library.adaptavist.com/entity/create-a-jira-issue-when-a-page-or-blog-post-is-approved-comala-workflows-integration). Please also change the parameters like project key and issue type before testing :-).

```
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.jira.JiraApplicationType
import com.atlassian.confluence.event.events.content.attachment.AttachmentCreateEvent
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import static com.atlassian.sal.api.net.Request.MethodType.POST

def event = event as AttachmentCreateEvent

def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
def attachment = event.getAttachment()

def body = new JsonBuilder([
        fields: [
                project    : [key: "XXX"],
                summary    : "Confluence Attachment Created - " + attachment.getFileName(),
                description: "Test description",
                issuetype  : [name: "Task"]
        ]
]).toString()

def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/issue")
        .addHeader("Content-Type", "application/json")
        .setEntity(body)

request.execute(new ResponseHandler<Response>() {
    @Override
    void handle(Response response) throws ResponseException {
        if (response.statusCode != 201) {
            log.error("Creating Jira issue failed: ${response.responseBodyAsString}")
        }
    }
})
```


author: Rob
body: Wow, thank you very much [@Hana Ku?erov?](/t5/user/viewprofilepage/user-id/1226304) !

I'll get everything setup (currently am not using ScriptRunner for Confluence, so will need to get that installed and setup) and test it out.

Thank you for working that up so fast!


Tags: confluence-server

jira

server