Mustache Variables

Integrations Hub for Jira allows custom variables that can be used when generating an integration request. Under the hood, we're using JSONPath and Mustache to extract and substitute variables for integration request.

It's currently possible to substitute the following:

  • Request URL

  • Request headers

  • Request body

  • Request Authorization

General usage

Variables are accessed by using the curly braces notation of Mustache. 

{{variable_name}} or for an object, the dot notated getter name without the "get".

Example: {{my_object.name}} . For the value of the getName() of the my_object variable

Value variables (Primitives/Strings ie.)

{{variable}} - Substitutes the variable value

Objects

{{object_name.user.name}} - Substitutes the object_name getUser().getName() value

Collections

Iterate through lists using the following Mustache pattern:

{{#title}}{{.}}{{/title}}

See Manage Arrays for further info

Formatting dates

Date objects can be formatted by using the following syntax. {{#date}}{{#format}}java_date_format_pattern{{/format}}{{/date}}

Example:

{{#issue.updated}} {{#format}} yyyy-MM-dd {{/format}} {{/issue.updated}} - Will format issue updated date. (since v.3.8.0)

Quick Formats (since v 4.4.0)

{{now.yearMonthDay}} = YYYY-MM-DD

{{now.monthDayYear}} = MM/DD/YYYY

{{now.monthDayYear2}} = MM/DD/YY

{{now.dayMonthYear}} = DD-MM-YYYY



Default variables

Default variables that are available for every iHub integration request are:

Variable

Description

Variable

Description

{{issue}}

The issue that triggered the request. (or was in context of the scheduled job). Note: Scheduled iHub integrations will only have an issue if an issue context scope has been defined.

{{now}}

Current date/time 

{{baseUrl}}

The Jira instance base url (since v1.0.1) 





Upper case on "U" in baseUrl







{{#comments.all}}

Get all comments for the issue

Usage: {{#comments.all}} {{body}} {{/comments.all}} = Iterate all comments, print its body

Note: add more attributes or change {{ body }} to any other comment attribut, see Jira JavaDoc

{{comments.latest}}

Get the latest comment object for an issue. 

Usage: {{comments.latest.body}} = Latest comment body 

{{comments.latest.authorApplicationUser.displayName}} = Latest comment author name
See the Java impl of the Comment interface here https://docs.atlassian.com/software/jira/docs/api/7.1.5/com/atlassian/jira/issue/comments/Comment.html each method is accessible using dot notation without the get. example getId() is accessible using {{comments.latest.id}}

For JSM public comments see Send only public comments from Jira Service Management

{{customfield_id}}

Get custom field name.

example; {{customfield_10003}} is a field called "Multi User Picker"

When using  {{customfield_10003}} in the URL or Body it will resolve to Multi User Picker.

To get the value of the custom field use the {{issue.customfield_10003}}

{{currentUser}}

Returns the current user as a ApplicationUser object

{{responseHeaders}}

{{responseHeaders.myVariable}} gives the myVariable response header. Note only available on child actions, but seen on the parents execution log.

{{attachments}}

Get the issue attachment(s) as a list. Can be used to post the attachment to other systems see Attachments - Multipart data or Body and How to send an attachment for more info.
Get the latest or first use:

  • {{attachments.first}}

  • {{attachments.last}} same as latest

  • {{attachments.latest}}

Properties on a attachment:

  • content type String base64encoded, ex {{attachments.last.content}}

  • authorKey type String, ex {{attachments.last.authorKey}}

  • authorObject type ApplicationUser, ex {{attachments.last.authorObject.username}}

  • created type Timestamp, ex {{attachments.last.created}}

  • filename type String, ex {{attachments.last.filename}}

  • filesize type Long, ex {{attachments.last.filesize}}

  • id type Long, ex {{attachments.last.id}}

  • mimetype type String, ex {{attachments.last.mimetype}}

  • zip type Boolean, ex {{attachments.last.zip}}

.asJson

You can use the .asJson method on any variable to retrieve the complete JSON object that the variable represents.

For example, if you have a data object like this: { "key": "hej", "more": {"extra": "abc","ex":"efg"}}, then using {{more.asJson}} with mustache notation will result in a JSON format containing {"extra": "abc","ex":"efg"}}.

This feature is useful when you need to extract subsets or entire chains of JSON responses.

This can be extra useful when filter incoming responses. Incoming Webhooks

 

String manipulation

Make a variable lowercase or uppercase

Lowercase "name":"{{issue.key.toLowerCase}}" Uppercase "name":"{{issue.key.toUpperCase}}" Trim "name":"{{issue.key.trim}}"





Defining custom variables from a response

You may define any number of variables from the response of the parent iHub integration that will be available for usage within the child's variable scope. 

Define custom variables by defining them in the variables section of the child action.



Set the variable name followed by the JSONPath expression.

See JSONPath for tutorials examples on how to define your JSON path for your use case

Automatic response variables



Issue object



Parent object





Using variables

Use the variable in an URL

Template URL: https://my_jira_instance_url/rest/api/2/issue/{{issue.key}}/comment

If operated on an issue with the key "QWERY-123" this will be evaluated as

https://my_jira_instance_url/rest/api/2/issue/QWERTY-123/comment



More variables