1
votes

I am able to connect to JIRA by JIRARestClient API and also able to get the information about issue but whenever I am trying to create issue by below code, getting this error "RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={issuetype=valid issue type is required}, errorMessages=[]}]}"

 IssueRestClient issueClient = new AsynchronousJiraRestClientFactory()
                                      .createWithBasicHttpAuthentication(baseUri, username, password).getIssueClient();

            IssueType issueType = new IssueType(null, 0L, "bug", false, "my issue", null);
            BasicProject basicProject = new BasicProject(null, "CPQ", 1L, null);

            IssueInput newIssue = new IssueInputBuilder(basicProject,issueType,"Mopendra").build();
            String issueCreated = issueClient.createIssue(newIssue).claim().getKey();

can anyone please help me on this?

2
I would guess your IssueType is not a valid type? - moilejter

2 Answers

3
votes

the cause is that you should use valid issue type that exists in your Jira and fill parameters correctly. You can fetch existing issue types and choose one you need. See

Jira issue type values for Rest api

3
votes

Please refer the below-working code. This should solve your problem.

//call method createIssue

  final String issueKey = myJiraClient.createIssue("YOUR_PRAJECT_NAME", 1L, "Issue created from Standalone App");

// method declaration

 private String createIssue(String projectKey, Long iType, String issueSummary) {

            IssueRestClient issueClient = restClient.getIssueClient();

            BasicProject cpqProject = null;
            IssueType issueType = null;

            try {
                final Iterable<BasicProject> projects = restClient.getProjectClient().getAllProjects().claim();

                System.out.println("======================getting all projoects======================");

                for (BasicProject project : projects) {
                    if(project.getKey().equalsIgnoreCase("cpq")) {
                        cpqProject = project;
                    }
                }

                Promise<Project> project = restClient.getProjectClient().getProject(projectKey);

                for(IssueType type : (project.get()).getIssueTypes()) {
                    if(type.getName().equalsIgnoreCase("Bug")){
                        issueType = type;
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            } 


            IssueInput newIssue = new IssueInputBuilder(cpqProject, issueType, issueSummary).build();

            return issueClient.createIssue(newIssue).claim().getKey();
        }