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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you found an answer to your issue? I am also looking for a script/API to clone an issue using REST APIs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.