1

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?

1
  • I would guess your IssueType is not a valid type? Commented Jul 27, 2018 at 7:20

2 Answers 2

3

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

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

Comments

3

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();
        }

1 Comment

@MopendraKumar, if this helps - you might want to consider accepting / upvoting the answer!

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.