Jira REST API Create Issue

Mitch Lu October 16, 2015

I'm using JIRA cloud.
Trying to use the API to create JIRA issues, but I got following error when I tried to set the summary field.

{"errorMessages":[],"errors":{"summary":"Field 'summary' cannot be set. It is not on the appropriate screen, or unknown."}}

final ClientConfig clientConfig = new ClientConfig();
final BasicAuthSecurityHandler basicAuthHandler = 
	new BasicAuthSecurityHandler("username", "password");
clientConfig.handlers(basicAuthHandler);
final RestClient winkClient = new RestClient(clientConfig);
final Resource resource = 
	winkClient.resource("https://cnwyjira.atlassian.net/rest/api/2/issue");
final ClientResponse response = resource
	.contentType(MediaType.APPLICATION_JSON)
	.accept(MediaType.APPLICATION_JSON)
	.post("{\"fields\":{\"project\":{\"id\":\"10001\"},\"issuetype\":{\"id\":\"10000\"},\"summary\":{\"JiraRestAPI\"}}}");

System.out.println(response.getEntity(String.class));


However, I was able to update the summary field by creating an new issue first via JIRA UI.

final Resource resource = winkClient
	.resource("https://cnwyjira.atlassian.net/rest/api/latest/issue/EDI-19604");
final ClientResponse response = resource
	.contentType(MediaType.APPLICATION_JSON)
	.accept(MediaType.APPLICATION_JSON)
	.put({\"fields\":{\"summary\":\"REST API Updated Summary\"}});

Please help! Thanks~

4 answers

1 accepted

1 vote
Answer accepted
Mitch Lu October 23, 2015

Thanks for the answers everyone.
I've found what caused this problem which was Authorization issue.
I should have done:

final RestClient winkClient = new RestClient();
final Resource resource =
	winkClient.resource("https://cnwyjira.atlassian.net/rest/api/latest/issue");
final String loginInfo = "username:password";
final String encodedLogin = new BASE64Encoder().encode(loginInfo.getBytes());
resource.header("Authorization", "Basic " + encodedLogin);

Instead of:

final ClientConfig clientConfig = new ClientConfig();
final BasicAuthSecurityHandler basicAuthHandler =
	new BasicAuthSecurityHandler("username", "password");
clientConfig.handlers(basicAuthHandler);
final RestClient winkClient = new RestClient(clientConfig);
final Resource resource =
    winkClient.resource("https://cnwyjira.atlassian.net/rest/api/latest/issue");
3 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 17, 2015

The clue is in the error message.

You can create issues with a summary with your "Create" code, so that tells us your "create issue" screen has the summary on it.  The error message is complaining that it can't find the field on your "edit" screen though.  So you need to add the summary to the edit screen.

Go to the project and drill down through its configuration (Issue type screen scheme -> screen scheme -> screen)

Mitch Lu October 17, 2015

I do have summary field setup in both create and edit view for the project. When I clicked "Create" button on Jira UI, the popup window has the summary field and is required. But if it's in create dialog, the first page has project and issue type fields and need to click "next" to see the summary field. Would that be the reason why I got the error?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2015

Sorry, I got my answer the wrong way around. The system thinks the summary is missing from create, not edit. The two step creation process should not be the problem though - REST should see the whole create screen in one go, with the summary on it, but that gives me a nagging doubt - what version of JIRA are you on? And is the summary on the create screen for *all* the issue types in that project?

Mitch Lu October 18, 2015

All issue types have summary field setup and I'm using Jira 7 cloud. Same error happened when I tried to set the description field... Looks like I can only set project and issue type fields that really makes me wonder if it's the two step creation cause the problem.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2015

I'm a bit stuck then - REST creates issues fine on my Cloud installation. I've used curl as shown in the docs, but I can't see how your code would fail

1 vote
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 16, 2015

Is your 'summary' field is available and enabled on "create issue" screen? It should be available and enabled, otherwise you cannot set it from REST API

0 votes
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 20, 2015

Hello Mitch Lu,

Thank you for your question.

Based on the source-code you have provided, we can notice you are setting up "summary" value as an object whereas the same should be a String.

.post("{\"fields\":{\"project\":{\"id\":\"10001\"},\"issuetype\":{\"id\":\"10000\"},\"summary\":{\"JiraRestAPI\"}}}");
{
    "fields": {
        "project": {
            "id": "10001"
        },
        "issuetype": {
            "id": "10000"
        },
        "summary": {
            "JiraRestAPI"
        }
    }
}

Please, refer to Examples of creating an issue that suggests the following data:

{
    "fields": {
       "project":
       { 
          "key": "TEST"
       },
       "summary": "REST ye merry gentlemen.",
       "description": "Creating of an issue using project keys and issue type names using the REST API",
       "issuetype": {
          "name": "Bug"
       }
   }
}

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

Suggest an answer

Log in or Sign up to answer