Updating the link of issues using JIRA API

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.

 

1 answer

0 votes

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);
}

 

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


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

Thank you :) its working.

@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. 

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,739 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot