How to create a task inside an Epic using Jira Rest API?

sachin.sharma April 14, 2020

Hi ,

I am using google form to create an automatic jira task using Jira REST API. But i want to create that task inside a predefined Epic, so that it becomes easy to track the tasks. 

 

Any help is highly appreciated. 

1 answer

0 votes
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 14, 2020

Hi @sachin.sharma 

In the issue you are creating, just add another field called"epic link" and set it with the epic you want.

Of course "epic link" should also be available in the create screen of the issue via the UI

sachin.sharma April 14, 2020

Hi @Nir Haimov ,

I have below json and code , can you please help how to use epiklink to pass the data. 

JSON:- 

{

  • "id":"customfield_10004",
  • "key":"customfield_10004",
  • "name":"Epic Link",
  • "custom":true,
  • "orderable":true,
  • "navigable":true,
  • "searchable":true,
  • "clauseNames":[
    1. "cf[10004]",
    2. "Epic Link"
    ],
  • "schema":{
    • "type":"any",
    • "custom":" W UP DATE",
    • "custom":true,
    • "orderable":true,
    • "navigable":true,
    • "searchable":true,
    • "clauseNames":[
      1. "cf[14600]",
      2. "FOLLOW UP DATE"
      ],
    • "schema":{
      • "type":"date",
      • "custom":"com.atlassian.jira.plugin.system.customfieldtypes:datepicker",
      • "customId":14600
      }
    },

 

CODE:- few lines of code to send data.

 

var formattedDate = ''
var data = {}
var fields = {}
fields.project = { "key": "ABC" };
fields.summary= summary;
fields.labels= [system];
fields.description= description;
fields.priority = {"name": severity };
if (deadline != ''){
formattedDate = Utilities.formatDate(new Date(deadline), "EST", "yyyy-MM-dd");
fields.duedate = formattedDate;

 

 

2. I am unable to find epiclink in UI. 

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 16, 2020

Hi @sachin.sharma ,

First, you have to add "epic link" to the UI create screen, otherwise it will not work via REST API.

Once you add it, it your API use this body as example:

{
"fields": {
"project": {
"id": "12200" //your project id
},
"summary": "Nir API Test",
"issuetype": {
"id": "10100" //this is the id of "task"
},
"customfield_10001": "JAT-641" //customfield_10001 is "epic link" and replace "JAT-641" with you epic key
}
}

That's it, very simple

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 16, 2020

check the id of your "epic link" field, it might be something else, but API body should be the same concept

sachin.sharma April 29, 2020

Thanks for your support @Nir Haimov . 

I did the same changes but getting below error.

"Exception: Request failed for https://test.net returned code 400. Truncated server response: {"errorMessages":[],"errors":{"customfield_10004":"Field 'customfield_10004' cannot be set. It is not on the appropriate screen, or unknown."}} (use muteHttpExceptions option to examine full response)"

Note:: Epic link field was customfield_1004.

 

My code is :-

 var fields = {}
fields.project = { "id": "18858" };
fields.customfield_10004= "ABC-81";
fields.summary= summary;
fields.labels= [system];
fields.description= description;
fields.priority = {"name": severity };
if (deadline != ''){
formattedDate = Utilities.formatDate(new Date(deadline), "EST", "yyyy-MM-dd");
fields.duedate = formattedDate;
}
if (reporterId){
fields.reporter= {"id": reporterId}
}
fields.environment = env;
fields.issuetype = {"name": "Task" }; 

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 29, 2020

Hi @sachin.sharma 

Your code is fine, the problem is in Jira.

You just need to add "Epic Link" to the create issue screen in Jira.

Te field have to be available in the UI action so you will be able to do it also from the REST API.

Let me know if you still encounter problems after adding the field.

sachin.sharma May 23, 2020

Hi @Nir Haimov ,

Since than i have been trying to find "How to create an epic link but no luck!"

One Quick question :- Creating an epic and using its url will work as epik link?

Please forgive me if i am asking something stupid.  

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 23, 2020

Hi @sachin.sharma ,

You tried to create epic via REST API or by the UI?

You can't use the epic link url as epic link, you need to use the epik issueKey (ABC-123)

sachin.sharma May 25, 2020

Yaah , it means i am in the right direction.

i have done the same thing , i have created an epic using UI and used its issue key in the code but didn't get success .  As you can check in my code above  https://community.atlassian.com/t5/Jira-questions/How-to-create-a-task-inside-an-Epic-using-Jira-Rest-API/qaq-p/1348846?utm_campaign=accept_as_solution_reminder&utm_content=view-answer&utm_medium=email&utm_source=atlcomm# 

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 25, 2020

@sachin.sharma i don't understand your code above, seems like you sending unnecessary data...

try first to create simple issue with the code i sent to you above, once that works, the rest is just a bit tuning with your code...

The code i sent you work, i tested it with my instance before sending to you, if that's not work for you, you are doing something wrong again....

Suggest an answer

Log in or Sign up to answer