Categories:
  1. What is JIRA
  2. JIRA VS Confluence
  3. Create Basic Creadetials in JIRA API
  4. Creating An Issue In A Sprint Using The JIRA REST API
  5. Create Issue using JIRA API
  6. JIRA Add comments to an existing ticket
  7. Create an attachment using JIRA API

Problem

When attempting to create a new issue that is already in a sprint using the REST API, you receive the following error:

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

This is using a JSON payload similar to the following with the POST /rest/api/2/issue endpoint:

{
    "fields": {
       "project":
       {
          "key": "SP"
       },
       "summary": "Sprint issue test",
       "description": "REST APIs are great.",
       "issuetype": {
          "name": "Bug"
       },
       "sprint": {
			"name": "Sprint 1"
		}
	}
}

Cause

The incorrect format is used for the sprint. Since sprints can share names and other features, the back end Sprint ID needs to be used.

Resolution

  1. Determine the custom field ID of the Sprint custom field. To do so, navigate to ⚙ > Issues > Custom fields and click ⚙ > View for the Sprint custom field. Take a look at your URL, you should see customFieldId=10001 or something similar – that is the ID of your Sprint custom field.
  2. Determine the ID of your Sprint. You can find this by hitting the endpoint /rest/agile/1.0/board/{boardId}/sprint, with your board ID being the value found in your URL under rapidView=. You can also find your board IDs using the endpoint /rest/agile/1.0/board.
  3. Once you have those values, you can assign a sprint value as if it were another custom field, using "customfield_XXXXX": YY, where XXXXX is your custom field ID from step 1, and YY is your sprint ID from step 1.

Here is an example of a correctly formed JSON to create an issue in a Sprint with ID 1:

{
    "fields": {
       "project":
       {
          "key": "SP"
       },
       "summary": "Sprint issue test",
       "description": "REST APIs are great.",
       "issuetype": {
          "name": "Bug"
       },
       "customfield_10001": 1
	}
}

Total Views: 1296

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *