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.
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.setRequestProperty("Authorization", "Basic " + encoded);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
System.out.println("Connection Response: " + connection.getResponseCode() + ": " + connection.getResponseMessage());
Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
String responseMessage = "";
for (int c; (c = in.read()) >= 0; responseMessage += ((char) c))
JSONObject responseMessageJson = new JSONObject(this.removeUTF8Mistakes(responseMessage));
this.newKey = responseMessageJson.getString("key");
this.fillIssue(this.newKey, responseMessageJson.getString("id"), responseMessageJson.getString("self"));
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?
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.
@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.
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