Create
cancel
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

How to add issuelinks in rest api ?

Hi everyone,

I followed this article :
https://confluence.atlassian.com/jirakb/how-to-use-rest-api-to-add-issue-links-in-jira-issues-939932271.html

But it doesn't work.

Here is my request :

{
"fields":{
"project":{
"key":"XX"
},
"summary":"test bug summary",
"description":"test bug description",
"issuetype":
{"id":"XXXXX"}
},
"update":{
"issuelinks":[
{
"add":{
"type":{
"name":"Blocks",
"inward":"is blocked by",
"outward":"blocks"
},
"outwardIssue":{
"key":"XX-967"
}
}
}
]
}
}

Can you please help me ?

3 answers

using the post('/rest/api/3/issueLink') method works like gangbusters. the "update" method not so much.

Hi,

Is there anyone that manage to create a multiple inward issue?

 

Extract of automation:

 

"update":
{"issuelinks":[{
"add": {
"type": {"name": "Blocks"},
"inwardIssue": {"key": "{{#createdIssues.get(7)}}{{key}}{{/}}"},
"inwardIssue": {"key": "{{#createdIssues.get(6)}}{{key}}{{/}}"},
"inwardIssue": {"key": "{{#createdIssues.get(5)}}{{key}}{{/}}"}
}

}]
}

0 votes

Hello,

Thanks for reaching out and fist it looks like you are Looking at the Jira Server Docs for the API formatting but your account is tied to a Jira Cloud address, The Formatting you are using for the data portion is for Jira Server and should be working without issue on a POST api/2/issue

If you are on Jira Server and this is failing what is the full syntax of the call you're using, and what is the Response error message you are getting when the call is failing?

For Jira Cloud:

The Documentation for the API can be found here:

There are a few changes needed for the call on the cloud side, You will want to use the version 3 endpoint for issue and do a POST /rest/api/3/issue

Then there is some additional formatting requirement on the Description where you currently have is set as "description":"test bug description", it should be formatted as follows:

    "description": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "text": "test bug description",
              "type": "text"
            }
          ]
        }
      ]
    },

So the Full data portion should look like this:

{
   "fields":{
      "project":{
         "key":"XX"
      },
      "summary":"test bug summary",
      "description": {
          "type": "doc",
          "version": 1,
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "type": "text",
                  "text": "test bug description"
                }
              ]
            }
          ]
        },
      "issuetype":{
         "name":"Bug"
      },
      "priority":{
         "name":"Major"
      }
   },
   "update":{
      "issuelinks":[
         {
            "add":{
               "type":{
                  "name":"Blocks",
                  "inward":"is blocked by",
                  "outward":"blocks"
               },
               "outwardIssue":{
                  "key":"XX-967"
               }
            }
         }
      ]
   }
}

Regards,
Earl

Hi Earl, thank you for your answer. You're right, I'm on Jira Cloud sorry. I tried with your answer but I still have the same problem on api/3 or api/2

{
"fields":{
"project":{
"key":"RD"
},
"summary":"test bug summary",
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "test bug description"
}
]
}
]
},
"issuetype":
{"id":"XXXX"}
},
"update":{
"issuelinks":[
{
"add":{
"type":{
"name":"Blocks",
"inward":"is blocked by",
"outward":"blocks"
},
"outwardIssue":{
"key":"XX-967"
}
}
}
]
}
}

Curl :

 


curl -X POST \
https://XXXXX.atlassian.net/rest/api/2/issue \
-H 'Authorization: Basic XXXXXXXXXXXXX' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"fields":{
"project":{
"key":"XX"
},
"summary":"test bug summary",
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "test bug description"
}
]
}
]
},
"issuetype":
{"id":"XXXX"}
},
"update":{
"issuelinks":[
{
"add":{
"type":{
"name":"Blocks",
"inward":"is blocked by",
"outward":"blocks"
},
"outwardIssue":{
"key":"XX-967"
}
}
}
]
}
}'

 

And the API send me this error :

 

{
"errorMessages": [],
"errors": {
"issuelinks": "Field 'issuelinks' cannot be set. It is not on the appropriate screen, or unknown."
}
}

Hey there,

The formatting looks good but the error you are encountering is related to the field:

"Field 'issuelinks' cannot be set. It is not on the appropriate screen, or unknown."

The noted field "issuelinks" is going to be the "Linked Issues" field on the system front end,  And it is either missing from the Create screen of the inward links project or the Edit Screen of the outward links project. 

Regards,
Earl

Hi, I have exactly same scenario. But my case the field is already there in on the screen.

Still getting below error :

 

"Field with id' issuelinks' and name 'Linked Issues' does not support operation 'outwardIssue' Supported operation(s) are: 'add'"

Hi,

it seems this update part simply doesn't work in the create part of the Cloud API. And if you submit a bug report it will rest in "gathering impact" peace for half a decade. So after a few hours and a dozen new gray hairs, here is how I solved it (first create issue, and then update/add a link):

 

def resultingCreatedIssue = post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.queryString("overrideScreenSecurity", Boolean.TRUE)
.body(
[
fields:
[
project: [
id: projectId
],
issuetype: [
id: myIssueTypeId
],
summary : samplingRequestSummary,
description: samplingRequestDescription,
(whateverIssueCFID): whateverValue

]
])
.asString().body

JsonSlurper slurper = new JsonSlurper()
def pasedJson = slurper.parseText(resultingCreatedIssue)
assert pasedJson instanceof Map
String createdIssueKey = pasedJson.key

post('/rest/api/3/issueLink')
.header('Content-Type', 'application/json')
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.body([
type:[ name: "Name of My Link" ],
inwardIssue: [key:targetKey],
outwardIssue: [key: createdIssueKey]
])
.asString().body

 

Hope it saves you guys a few hours ;)

Like BBury likes this

@Pujanito Zii , thank you. @Atlassian take note.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

545 views 15 18
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