Updating the link of issues using JIRA API

Joao Brandao November 1, 2017

Hey mates,

I am trying to add/update the link in issue using JIRA API. But i am getting Bad request (error 400)

 

JSON code:

{
"update": {
"issuelinks": [{
"type": {
"name": "Relates"
},
"inwardIssue": {
"key": "XPTO-29432"
},
"OutwardIssue": {
"key": "XPTO-29072"
}
}
]
}
}

 

URI: https://XPTO.jira.com/rest/api/2/issueLink 

 

Code i am using to PUT

HttpPut put = new HttpPut(uri);
put.setHeader("Content-Type", "application/json");
put.setHeader("Authorization", "Basic " + args.getJiraAuthToken());
HttpEntity entity = new ByteArrayEntity(json.getBytes("UTF-8"));
put.setEntity(entity);
HttpResponse response = httpClient.execute(put);

Note:

my json object is the one i tell u in this text.

 

Do you have any idea what is going on? I already try with POST but still not working.

 

2 answers

1 accepted

2 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 1, 2017

Hello,

You can install on your Jira instance Rest Api Browser Addon  and check if your json is correct. If your Json is not correct Jira will return you a message about the error.

Or you can add to your code something like this to see the exact message of the error:

 BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));

String output;
while ((output = br.readLine()) != null) {
System.out.println(output);
}

 

Joao Brandao November 1, 2017

Thank you :)
I am getting this message erro:

Code: 400

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

i change my uri to: https://xpto.jira.com/rest/api/2/issue/XPTOISSUE-29432


Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 1, 2017

You need to use a different REST API for linking issues. You can read about it here:

https://docs.atlassian.com/jira/REST/server/#api/2/issueLink

Joao Brandao November 1, 2017

Thank you :) its working.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 1, 2017

@Joao Brandao

If you think, the answer was right, please accept it as solution.

Answers to solved questions can be found more easy by other users who might have the same problem in the future. 

1 vote
Tibor Maseras Fraga April 17, 2019

Thx for the answer.

This works fine:

{
    "type": {
        "name": "Duplicate"
    },
    "inwardIssue": {
        "key": "xxx"
    },
    "outwardIssue": {
        "key": "xxx"
    },
    "comment": {
        "body": "Linked related issue!"
    }
}

You need chance "xxx" for your Jira key.

 

;)

Chris Liddle February 22, 2020

Hi - i can create issues fine, but am receiving the following error when trying to link 2 issues via /rest/api/2/issueLink API (JIRA VERSION -Jira v8.7.1):

 "errorMessages": [
"Unrecognized field \"fields\" (Class com.atlassian.jira.issue.fields.rest.json.beans.LinkIssueRequestJsonBean), not marked as ignorable\n at [Source: org.apache.catalina.connector.CoyoteInputStream@3c1d6fc7; line: 2, column: 16] (through reference chain: com.atlassian.jira.issue.fields.rest.json.beans.LinkIssueRequestJsonBean[\"fields\"])"
]
}

Json:

 {  "update":{ "issuelinks":[ { "add":{ "type":{ "key":"is blocked by" }, "inwardIssue": { "key": "BLAH-62" }, "outwardIssue":{ "key": "BLAH-61" }, "Comment":{ "body":"Blocked related issue! YIPEEE" } } } ] } }

 could someone help me out please?

Thanks.

Jonathan Vezinat May 26, 2021

As far as i know, you can only update one link at a time. So, put the inward and outward issue into separate rest calls to the API

Carla James June 10, 2022

I tried with PUT and Update after creating the issue, no luck. What worked in the end was using the issueLink endpoint.  I run my code in VBA and here is a snippet

.Open "POST", "https://Your server/jira/rest/api/2/issueLink", False

 

And the data  that I send is:

{
"outwardIssue": {
"key": "XXXX"
},
"inwardIssue": {
"key": "XXXX"
},
"type": {
"name": "Duplicate"
}
}

 

Without the Type it doesnt work you have to add it

Suggest an answer

Log in or Sign up to answer