Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Clone Issue in java with rest api

Hello,

 

I would like to clone an issue using rest api. I've  already checked on Internet and for what I've found there is no easy way to do this. I'm getting JSONObject from a get request and I would like to create a clone of this issue using this json, Therefore I do it manually. However I'm facing 2 issues. 

1) There is a lot of customfields with null value, I did a recursive loop to get rid of all of these. Is there a way to just ignore them when value is null, otherwise not ?

 

2) It's not simple tickets. I mean there is issuelinks, attachment ... I found that I have to use many rest apy to perform it, is that right ? It means for each jsonObject I have to manually detect these special fields and then use the correct api ? (https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/?_ga=2.6947120.32031392.1541399805-1750503480.1538466569#api/2/field-createCustomField)

 

I would like to precise that it's not an authentification problem. I can succesfully create a simple issue with only project, summary, description and issuetype.

 

Thank you.

2 answers

1 accepted

0 votes
Answer accepted

Yes I simply delete all custom fields or null fields. Thank you

I do not understand.

I am trying to clone a JIRA ticket. How do accomplish this, And would you mind sharing code? Are you using JIRA module in your Python script?

Hi here is a part of my code. I'm not using any module. I'm using java. You just have to reach rest api with HTTP request.

 

URL jiraURL = new URL(this.hubModel.getUrl() + "/rest/api/2/issue/");
URLConnection urlConnection = jiraURL.openConnection();

String login = this.hubModel.getIdUser() + ":" + this.hubModel.getPwUser();
byte[] authEncBytes = Base64.encodeBase64(login.getBytes());
String encoded = new String(authEncBytes);

byte[] dataBytes = newJsonObjectIssue.toString().getBytes("UTF-8");

// establish connection and request properties
connection = (HttpURLConnection) jiraURL.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization", "Basic " + encoded);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(dataBytes);

System.out.println("Connection Response: " + connection.getResponseCode() + ": " + connection.getResponseMessage());

wr.flush();
wr.close();

Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
String responseMessage = "";
for (int c; (c = in.read()) >= 0; responseMessage += ((char) c))
;
System.out.println(responseMessage);
JSONObject responseMessageJson = new JSONObject(this.removeUTF8Mistakes(responseMessage));
this.newKey = responseMessageJson.getString("key");
this.fillIssue(this.newKey, responseMessageJson.getString("id"), responseMessageJson.getString("self"));

Yikes. I only know Python. I would have to read/learn your code and try to figure it out and how to use it. I will certainly try. In order to run this, did you need any libraries or modules from Jira when you compiled your code with jvm?

Have you found an answer to your issue? I am also looking for a script/API to clone an issue using REST APIs.

I Max,

 

There is no api to do so, you have to do it manualy, also create a new issue with extracted info from your old issue.

Like Cameron Stubber likes this

This is basically what I am about to do also. Seems like you need to read the original, copy all the custom field data, prepare a new issue, and then create it. Also, if you want to link it, use the return data from the Create Issue to do the link back.

Like # people like this

Hi Cameron. I am still looking how to do this. I do need to read the original, copy some custom field data, and prepare a new issue. I am a Python dev, and not a Java developer. But at this point, this need is still quite important to our team, and we want to find a solution to it. Can we work together on this?

 

Max

Hi Max,

Sure, I can share some things with you. I am also doing it in Python, my approach is to just use a computer/server/virtual machine and schedule tasks which run python scripts every few minutes. These scripts then check issues and perform actions based on it. It was much easier than writing a JIRA Addon in Java.

Like Jean-Marc Junique likes this

That would be awesome. I appreciate it so much. Our customers open some JIRA's which we have to clone and attach/add some details from the original in our new JIRA ticket. Bro, this will be such a life saver.

Any progress made Cameron? How is it going for you?

@Max so I completely missed notifications about this... and I guess its been quite some time now so either you solved your problem or moved on in life or something haha :)

 

I did solve this issue with Python - I wrote some scripts which downloaded all the tickets from like 10 projects in Jira Cloud, and downloaded all the attachments, and then created new tickets all over again with the metadata in On-Prem/Server.

Suggest an answer

Log in or Sign up to answer
TAGS

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