Skip to content

Instantly share code, notes, and snippets.

@matts-mpg
Last active August 10, 2019 03:40
Show Gist options
  • Save matts-mpg/ddbdcb23f52f96178cfa614423d486ca to your computer and use it in GitHub Desktop.
Save matts-mpg/ddbdcb23f52f96178cfa614423d486ca to your computer and use it in GitHub Desktop.
Fully working from the Confluence Scriptrunner console this will create a new Epic in PROJECT.
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.jira.JiraApplicationType
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 appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
String body = new JsonBuilder([
fields: [
project : [key: "PROJECT"],
"customfield_10002" : "more",
summary : "lists are hard",
description : "ononononon",
issuetype : [id: 10000L]
]
]).toString()
def request = applicationLinkRequestFactory.createRequest(POST, "/rest/api/2/issue")
.addHeader("Content-Type", "application/json")
.setEntity(body)
def jsonSlurper = new JsonSlurper()
def createdIssue = jsonSlurper.parseText(request.execute())
return createdIssue.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment