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

Meera January 4, 2018

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 4, 2018

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?

Meera January 4, 2018

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 4, 2018

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.

Meera January 4, 2018

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

1 vote
Answer accepted
Dzmitry Hryb _Deviniti_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 16, 2018

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

Bertrand Drouhard March 14, 2019

Intenso documentation page about API moved to https://deviniti.com/support/addon/server/issue-templates/latest/app-integrations/

In their example, change customField_10000 by your Templates custom field, and change the associated value with the Template ID that you want to use for creation.

Like Dzmitry Hryb _Deviniti_ likes this
2 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2018

Hello,

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

Meera January 4, 2018

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 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