Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add issuelinks in rest api ?

Tech Habiteo August 22, 2019

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

0 votes
BBury March 2, 2021

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

0 votes
Benoit
Contributor
January 5, 2021

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
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 23, 2019

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

Tech Habiteo September 24, 2019

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."
}
}
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 24, 2019

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

Tridib Choudhury
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 1, 2020

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'"

Puján Z
Contributor
November 24, 2020

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
BBury March 2, 2021

@Puján Z , thank you. @Atlassian take note.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian community, loom ai, atlassian loom ai, loom, atlassian ai, record recaps of meetings, meeting recaps, loom recaps, share meeting recaps,

Loom’s guide to great meetings 📹

Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.

Register today!
AUG Leaders

Atlassian Community Events