Jira REST API Create Issue

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

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");

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

1 votes

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)

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?

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?

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.

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

0 votes

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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

523 views 1 15
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot