2

I am trying to write a method to delete an issue in JIRA.

I already have methods to create and update issues, but I cannot find any documentation on how to delete an issue using Java.

How can I delete a JIRA issue from a Java application?

2 Answers 2

1

You can try delete from IssueService: https://docs.atlassian.com/jira/latest/com/atlassian/jira/bc/issue/DefaultIssueService.html#delete(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.bc.issue.IssueService.DeleteValidationResult)

Sign up to request clarification or add additional context in comments.

Comments

0

You can try this:(here in this class I am getting specific user created issues by using JQL and after getting the response, I am deleting all of them one by one)

public class DeleteJiraIssuesHelper {
       private InputStream inputStream;
       private JsonReader jsonReader;

public void deleteJiraIssues() throws JiraDeleteIssueException, IOException {   
String JQL="your jql query";
try {
  URL url = new URL(
      "your jira url/rest/api/latest/search?jql="+JQL);
  String userpass = "UserName" + ":" + "Password";
  String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("GET");
  conn.setRequestProperty("Authorization", basicAuth);
  conn.setRequestProperty("Content-Type", "application/json");
  if (conn.getResponseCode() != 200) {
    throw new JiraConnectionException("Failed : HTTP error code : " + conn.getResponseCode());
  }
  conn.getResponseMessage();
  inputStream = conn.getInputStream();
  jsonReader = Json.createReader(inputStream);

  JsonObject jsonObject = jsonReader.readObject();
  int no = jsonObject.getInt("total");

  JsonArray jsonArray = jsonObject.getJsonArray("issues");
  List<String> issueList = new ArrayList<>();
  for (int i = 0; i <= no - 1; i++) {
    JsonObject jsonObject2 = jsonArray.getJsonObject(i);
    String key = jsonObject2.getString("key");
    issueList.add(key);
  }
  conn.disconnect();

  HttpURLConnection httpCon = null;
  for (int i = 0; i < no; i++) {
    URL url2 = new URL(
        "Jira url/rest/api/latest/issue/" + issueList.get(i));
    httpCon = (HttpURLConnection) url2.openConnection();
    httpCon.setRequestProperty("Authorization", basicAuth);
    httpCon.setDoOutput(true);
    httpCon.setRequestProperty("Content-Type", "application/json");
    httpCon.setRequestMethod("DELETE");
    httpCon.connect();
    httpCon.getResponseCode();
    httpCon.disconnect();
  }

} catch (IOException ex) {
  throw new JiraDeleteIssueException("MalformedURLException: " + ex);
} finally {
  inputStream.close();
  jsonReader.close();
  }
 }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.