Create story that is linked to an epic using rest api

kuldip naik April 4, 2019

Hi

I am able to create an epic - key WHSAR-769 but I am unable to create a story using rest. I could not find "User Story " on my jira instance - https://wim-jira.xxxx.com/rest/api/2/issuetype

 

Here is what I used to create story and of course it fails with

 

{
"fields": {
"project": {
"key": "WHSAR"
},
"parent":
{
"key": "WHSAR-769"
},
"summary": "2EUT",

"customfield_19545": {
"Option id": "38679",
"value": "Prerequisites"
},

"customfield_10183": 7,

"customfield_15891": {
"Option id": "38719",
"value": "2EUT"
},

"customfield_11709": "Acceptance of Project kick off date and the resources details from app manager.",
"duedate": "04-01-19",


"description": "Ensure app manager has confirmed project kick off date and resource details for the application being migrated.",
"issuetype": {
"id": "5"
}

}
}

2 answers

1 accepted

0 votes
Answer accepted
kuldip naik April 4, 2019

If anyone from Atlassian following this forum and cares about users - you should atleast follow stackoverflow theme that allows you to put code and formatting. I can't even find decent JSON formatting for my questions.

So the answer:

You can't create story that is connected to a Epic in one shot. you have to create story first and then update the Epic link on that Story (issue)

Of course during story creation - you can't use the parent id. Below code worked for me:

{
"fields": {
"project": {
"key": "WHSAR"
},

"summary": "2EUT",

"customfield_19545": {
"Option id": "38679",
"value": "Prerequisites"
},

"customfield_10183": 7,

"customfield_15891": {
"Option id": "38719",
"value": "2EUT"
},

"customfield_11709": "Acceptance of Project kick off date and the resources details from app manager.",
"duedate": "04-01-19",


"description": "Ensure app manager has confirmed project kick off date and resource details for the application being migrated.",
"issuetype": {
"name": "User Story"
}

}
}

----------------

 

then on the story issue

https://wts-jira.xxxxxx.com/rest/api/2/issue/1154615 
{"fields": {"customfield_12702":"WHSAR-769"}}

1 vote
Tim Oppenlander August 19, 2020

"You can't create story that is connected to a Epic in one shot"

I was able to find a way to do it.   This thread showed me how to create a story and link it to an Epic in one transaction

This worked for me, but I stumbled over two things:

1.  The customfield_nnnnn is different for every system.  I had to use the get field names API to find the "Epic Link" field ID:  http://localhost:8080/rest/api/2/issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}, as documented here:  https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/.  

2.  The content of the custom field has to be set to the EPIC ID, not the EPIC name.  For instance, if my project ID is TEST, and the EPIC is TEST-6, with a description of EPIC1, then I would use TEST-6, not EPIC1, in the JSON.

Hope that helps.

Suggest an answer

Log in or Sign up to answer