The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating subtask using java rest api client

samkit jain
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 18, 2019

Hi All,

I am working on a requirement where I have to create an issue and multiple sub task for that issue using java rest client for jira.

when I am trying to create an issue using sub-task issue type id, it is giving me error that parent Id or key not mentioned.

I am using JIRA Rest API v5.1.0, but in the Inputbuilder class, there is no option to state the parent key or id.

 

Can anybody please help?

P.S : Due to confidentiality constraint, I cannot copy my code here. Any help would be highly appreciated.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Tarun Sapra
Community Champion
March 18, 2019

Hello @samkit jain 

Please share your code sample and also the link to the Jira REST client docs

samkit jain
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 20, 2019

Hi @Tarun Sapra ,

I cannot share the code due to client confidentiality agreement. However I was able to resolve the error.

following thing worked for me:

While creating IssueInputBuilder Object for Subtask issue, I set a parameter name FieldInput.

FieldInput fi = new FieldInput("parent", Object)

This Object is a ComplexIssueInputFieldValue type.

Yufei_Gong__US_-_ADVS_
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 14, 2020

Hi @samkit jain 

 I am meeting the same issue here, Could you please share a sample of data you put in this ComplexIssueInutFieldValue type? thx.

Deleted user
April 29, 2020

Here's a (non-performant) snippet showing how to create an epic and then make a subtask for it:

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.domain.BasicIssue;
import com.atlassian.jira.rest.client.api.domain.input.ComplexIssueInputFieldValue;
import com.atlassian.jira.rest.client.api.domain.input.IssueInput;
import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
public class Application {
  public static void main(String[] argsthrows IOExceptionURISyntaxException {
    final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    URI jiraServerUri = new URI("my jira base url");
    final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "username""password");
    try {
      IssueInput epicInput = new IssueInputBuilder()//
          .setProjectKey("Project Key")//
          .setIssueTypeId(36L)//
          .setSummary("Epic W/Rest API")//
          .setDescription("my epic description")//
          .build();
      BasicIssue epicIssue = restClient.getIssueClient().createIssue(epicInput).claim();
      IssueInput subTaskInput = new IssueInputBuilder()//
          .setProjectKey("Project Key")//
          .setIssueTypeId(5L)//
          .setSummary("Subtask W/Rest API")//
          .setDescription("my subtask description")//
          .setFieldValue("parent"ComplexIssueInputFieldValue.with("key"epicIssue.getKey()))//
          .build();
      restClient.getIssueClient().createIssue(subTaskInput);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      restClient.close();
    }
  }
}

 you can query things like id of subtask issue type etc by getting 

${base jira url}/rest/api/2/issue/createmeta

you'll need the following dependencies:

<dependency>
  <groupId>com.atlassian.jira</groupId>
  <artifactId>jira-rest-java-client-app</artifactId>
  <version>5.2.1</version>
</dependency>
<dependency>
  <groupId>io.atlassian.fugue</groupId>
  <artifactId>fugue</artifactId>
  <version>4.7.2</version>
  <scope>provided</scope>
</dependency>

and the following repository connections:

<repository>
  <id>atlassian-public</id>
  <url>https://m2proxy.atlassian.com/repository/public</url>
  <snapshots>
    <enabled>true</enabled>
    <updatePolicy>daily</updatePolicy>
    <checksumPolicy>warn</checksumPolicy>
  </snapshots>
  <releases>
    <enabled>true</enabled>
    <checksumPolicy>warn</checksumPolicy>
  </releases>
</repository>
<pluginRepository>
  <id>atlassian-public</id>
  <url>https://m2proxy.atlassian.com/repository/public</url>
  <releases>
    <enabled>true</enabled>
    <checksumPolicy>warn</checksumPolicy>
  </releases>
  <snapshots>
    <checksumPolicy>warn</checksumPolicy>
  </snapshots>
</pluginRepository>