How to create JIRA issue ticket from a template using REST api?

I want to create JIRA Change Request Ticket using a template. 

Below is the format of the data sent to JIRA. I have tried using the projectTemplateKey parameter along with this request. But I am not sure if this is the right way. 

Could anyone please help? 

payload =
{
fields:
{
project: { key: "CRQ"},
customfield_15630: "SampleTemplateName",
summary: "Testing",
customfield_17679: "N.A" ,
customfield_14530:"2018-06-17T00:00:00.0+0000 ",
customfield_14531: "2018-06-17T00:00:00.0+0000 " } }

 

3 answers

2 accepted

2 votes

I'm not sure what you mean by "template".  Your call to create an issue looks ok to me, so I'm not sure what's going wrong.

The xml you've given is of no use for REST calls, so I'm guessing I am missing some part of a process you are going through that you've not explained.

As an aside, projectTemplateKey is not a parameter I recognise, could you explain where you found it in the REST API docs and what you think it does?

The JIRA Change request has a field called 'Template' , so when it is selected some fields are automatically populated and related services and subtasks are created along with the ticket.

So I am trying to create a ticket from a template using REST API.

But when tried to add the template value as below, 

customfield_15630: "SampleTemplateName",

 

Error message from the JIRA response

400 Bad Request: {"errorMessages":["We can't create this issue for you right now, it could 
be due to unsupported content you've entered into one or more of the issue fields.
If this situation persists, contact your administrator as they'll be able to access more
specific information in the log file."],"errors":{}}


I would like to know if creation of ticket from template is possible using REST api ?

 

I found the projectTemplateKey parameter from here. Not sure if it is related. 

https://community.atlassian.com/t5/Answers-Developer-Questions/Create-a-project-template-in-JIRA-and-use-this-project-template/qaq-p/468079

Alexey Matveev Community Champion Jan 04, 2018

Do you mean that you want to create a  Service Desk Request? Then you should use Jira Service Desk API to create a request.

That is how you should create it

https://developer.atlassian.com/cloud/jira/service-desk/rest/#api-request-post

The post you linked to your message is about project templates. They do exists in Jira. Project templates let administrators create projects with certain workflow schemes, screen schemes etc. You do not need it.

Ah, I think that helps me understand the problem.

You are NOT trying to create an issue from a "template", you have a field that has some hacks on it that manipulate the user's browser into filling fields for them.

You have not configured REST calls to do the equivalent in background code.

In reality your "template" field is simply a custom field.  Your REST call is not replicating all the logic you've set up in your template hack, so it's failing.

If you re-read the link you've given again, you should see that the projectTemplateKey is a function of creating projects.  Projects are not issues.

It is pretty clear now. Thanks @Nic Brough [Adaptavist] and @Alexey Matveev

If I'm not mistaken, you're using Issue Templates - that's why @Alexey Matveevand @Nic Brough [Adaptavist] were a bit confused :)

The error message that you've attached was related to a bug, when more than one app's post function were stacked and conflicted with themselves. This has been fixed recently - simply update the app at the Marketplace, and the error should be gone.

Your payload is lacking an issueType parameter, which is required for Jira to create an issue. The templateProjectKey parameter is related to project templates, not issue templates.

Here's an example of a proper issue creation from a template via REST API: https://intenso.atlassian.net/wiki/spaces/IT/pages/110270245/NEW+Create+via+Rest+API

2 votes
Alexey Matveev Community Champion Jan 04, 2018

Hello,

What REST API do you use? What is project template key?

I use JIRA API endpoint '/rest/api/2/issue' . 

<item><title>[TMPL-167] NTW-8 [Network_Interface_configuration]</title><link>https://jiraqa.com/browse/TMPL-167</link><project id="15980" key="TMPL">Templates</project><description>Test</description><environment/><key id="492895">TMPL-167</key><summary>NTW-8 [Network_Interface_configuration]</summary> 

Here's the xml format of the template I want to use for the ticket. 

Alexey Matveev Community Champion Jan 04, 2018

Kindly try to answer @Nic Brough [Adaptavist]question about the template. I also can not figure out what you are up to with the template.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 21, 2018 in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

1,242 views 10 18
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