Skip to main content

Apply Templates via Jira Automation or API

When creating issues through Automation or an API, you might need to apply templates. For instance, if tests fail in Xray, an issue can be automatically generated. In such cases, this feature ensures that templates are seamlessly applied to the auto-created issues.

Apply Template via Automation

With Jira automation, you can apply templates to issues. Below are the steps:

Generate token

  1. Go to “Apps” on the top navigation bar

  2. Go to “Manage Your Apps”

  3. Open “Issue Templates Config” from the left bar

  4. Go to “API Tokens”

Issue-templates-api-tokens.png

API Tokens

  1. Click “Generate Token”

  2. Fill in the token label and expiration date

  3. Copy the token

Note: once the generate token window is closed, token cannot be viewed again.

Create Automation Rule

  1. Create an automation that adds Web request URL after creating a new issue. Please see https://www.atlassian.com/software/jira/guides/automation/tutorials#manage-automation-rules for Jira automation tutorial.

  2. Add a “Send web request” component as rule action.

image-20241111-231618.png

Web request component

  1. Fill in the Action with the following:

Screenshot 2024-11-12 at 14.47.46-20241112-065745.png

Web Request params

To ensure that the rule does not overwrite important data, you can add a condition to check if issue description field emply or has only short value.

check-description-length.png

Add if condition to check description field

a. Web request URL: [URL]

To get the web request URL, go to back to API Tokens page: Top Nav → Manage Your Apps → Issue Templates Config → API Tokens and copy the Web request URL.

image-20241112-041146.png

Web request URL

b. HTTP method: POST

c. Web request body: Custom data

d. Custom data:

CODE
{ 
 "issueKey": "{{issue.key}}",
 "templateId" : "IT-V2-039e00da-3703-4d2f-a7d3-6490ece4880a" 
}

  • issueKey is the key of the newly created issue. It is auto-generated by Jira. You can leave this as is.

  • templateId is the template you would like to apply. To get the templateId, please navigate to the Issue Templates Pro app → Click action (…) → Copy templateId.

Issue Templates Pro menu

Action menu

e. Headers (optional):

  • Key: Authorization

  • Value: Bearer [token]

Paste the generated token in Value field, after Bearer.

image-20241112-040433.png

Web Request authorization header

Apply Template with API

Following similar approach, you can also apply template with API. In this example, we are using Postman.

Generate token

Please see above how to generate token: Apply Templates via Jira Automation or API | Generate-token .

Configure the API

  1. Use the POST URL with the web request URL.

To get the web request URL, go to Apps on the top navigation bar → Manage Your Apps → Issue Templates Config from the left bar → API Tokens → Copy the Web request URL.

image-20241112-041146.png

Web request URL

  1. Fill in the generated token.

Screenshot 2024-11-07 at 20.41.17-20241107-124204.png

Postman - Authorization tab

  1. Use the following parameters inside Body.

CODE
{ 
 "issueKey": "{{issue.key}}",
 "templateId" : "ITT-V2-039e00da-3703-4d2f-a7d3-6490ece4880a" 
}

templateId is the template you would like to apply. To get the templateId, please open the Issue Templates Pro app → Click action (…) → Copy templateId.

image-20241107-124753.png

Postman - Body tab

HTTP Response and Error

The summary of the HTTP response codes is given below.

HTTP Response Code

Remarks

200

Template is successfully applied to the issue.

401

Wrong authorization or wrong token.

404

Template is not found.

400/424

Issue is not found.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.