Hey folks, I’m stuck trying to make Jira tickets automatically using Java. I’m working with the JiraRestClient and I’ve got these libraries:
compile 'com.atlassian.jira:jira-rest-java-client-api:5.2.4'
compile 'com.atlassian.jira:jira-rest-java-client-core:5.2.4'
Here’s my code to make new issues:
@SneakyThrows
public TicketInfo makeNewTicket(TicketCategory category) {
return jiraApi.getTicketHandler().makeTicket(
TicketInput.fillFields(
new DataField(TicketFieldId.PROJECT, PROJECT_ID),
new DataField(TicketFieldId.CATEGORY, category.getCode()),
new DataField(TicketFieldId.TITLE,
String.format('Add %s to %s collection', 'example',
'test')),
new DataField(TicketFieldId.DETAILS, 'ticket details')
)).onFail(error -> logger.error(error.getMessage()))
.get();
}
But when I run it, I get this error:
RestClientException: status 400, errors: {category=Can't create value for [class ResourceRef] from number; no matching constructor, project=project needed}
I tried using older versions of the client but no luck. Any ideas what I’m doing wrong?
I had a similar problem a while back when working with the Jira REST API in Java. The error message you’re receiving usually points to a mismatch between the data type the API expects and the values you’re providing. It seems that the project field might be expecting a project key (for example, “PROJ”) instead of an ID, and the category field might need a more structured object, like a ComplexIssueInputFieldValue.
Try revising your DataField for the project to use the key and adjusting the category field accordingly. Also, verify your field IDs and authentication settings; sometimes even small discrepancies can trigger a 400 error.
I’ve encountered this issue before when working with the Jira REST API. The problem likely stems from how you’re passing the project and category values. For the project, try using the project key (a string like ‘PROJ’) instead of an ID. As for the category, Jira expects a more complex object structure.
Here’s a modified version of your code that might work better:
IssueInputBuilder issueInputBuilder = new IssueInputBuilder();
issueInputBuilder.setProjectKey("PROJECT_KEY")
.setSummary(String.format("Add %s to %s collection", "example", "test"))
.setDescription("ticket details")
.setIssueType(IssueType.NAME_TASK);
if (category != null) {
issueInputBuilder.setFieldValue("category", ComplexIssueInputFieldValue.with("name", category.getName()));
}
IssueInput issueInput = issueInputBuilder.build();
BasicIssue createdIssue = jiraRestClient.getIssueClient().createIssue(issueInput).claim();
This approach should resolve the data type mismatches causing your 400 error. Remember to replace ‘PROJECT_KEY’ with your actual project key.