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

Jira cloud REST create issue and issuelink

imran I'm New Here Nov 27, 2021

I'm trying to create an issue, issuelink and copy attachment from triggered issue at the same time using scriptrunner.
For now, the code below are able to create issue and attachment, but I can not link the issue I created, does someone ever deal with this situation?

import org.apache.http.entity.ContentType;

def issueKey = issue.key
def result = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')

def projectkey = "PILOTLV"
if ( == "10124"){
projectkey = "SPCLRQ"

def issuetypekey = "10018"
def ticketno = result.body.fields.customfield_10060
if ( == "10015"){
issuetypekey = "10017"
ticketno = result.body.fields.customfield_10059

def description = result.body.fields.description
def summary = result.body.fields.summary
def sysname =

// create issue 
def createReq ="/rest/api/2/issue")
        .header("Content-Type", "application/json")
        fields: [
        summary : summary,
        description: description,
        customfield_10078: [
        id: sysname
        customfield_10060: ticketno,
        project : [
        key: projectkey
        issuetype : [
        id: issuetypekey
        update: [
        issuelinks: [
            add: [
                    name: "Blocks",
                    inward: "is blocked by",
                    outward: "blocks"
                outwardIssue: [
                    key: issuekey

assert createReq.status >= 200 && createReq.status < 300

def clonedIssue = createReq.body

// copy attachments

if (issue.fields.attachment) {
    issue.fields.attachment.collect { attachment ->
        def url = attachment.content as String
        url = url.substring(url.indexOf("/secure"))
        def fileBody = Unirest.get("${url}").asBinary().body
        def resp ="/rest/api/2/issue/${}/attachments")
                .header("X-Atlassian-Token", "no-check")
                .field("file", fileBody, ContentType.create(attachment['mimeType'] as String), attachment['filename'] as String)
        assert resp.status >=200 && resp.status < 300

And there is a minor question, I found that the attachment name on new issue can not display Chinese character Looks like I'm missing library

1 answer

0 votes
Hana Kučerová Community Leader Nov 28, 2021

Hi @imran ,

welcome to the Atlassian community!

I believe the link creation needs to be the second step - first of all you create a new issue and then you send another request for linking the issues together.

Suggest an answer

Log in or Sign up to answer

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