JMWE Cloud: How to query the Assets API using Nunjucks

JMWE Cloud: How to query the Assets API using Nunjucks

Summary

Some use cases in Jira Misc Workflow Extensions (JMWE) for Cloud require querying Assets (formerly Insight) data. Because Asset data is stored externally to your Jira site, you must use the Atlassian Assets API (api.atlassian.com) rather than your standard Jira instance URL. This article provides the Nunjucks script and configuration steps required to perform an Assets Query Language (AQL) query via an API call.

Environment

  • Jira Service Management Cloud

  • Jira Misc Workflow Extensions (JMWE) for Cloud

  • Assets (formerly Insight)

Prerequisites

Before configuring the script, ensure you have the following information:

  • User Email: The email address of the Atlassian account that will perform the request.

  • Atlassian API Token: An API token generated for the account above. See Manage API tokens for your Atlassian account | Atlassian Support.

  • Assets Workspace ID:

    1. Open your browser and navigate to: https://<yourinstance>.atlassian.net/rest/servicedeskapi/assets/workspace

    2. Locate and copy the workspaceId value.

Solution

To query Assets using Nunjucks, you can use the callRest filter within a scripted post function (such as Build-your-own (Nunjucks scripted) post function).

1. Configure the script

  1. Add the desired JMWE post function to your workflow transition.

  2. In the script editor, paste the following Nunjucks template:

{% set email = "your-email@example.com" %} {% set token = "your-api-token" %} {% set wsid = "your-workspace-id" %} {% set query = "Key IN ('XX-01')" %} {{ "https://:email::key@api.atlassian.com/jsm/assets/workspace/:wsid/v1/object/aql" | callRest( params={"emai":email, "key":token, "wsid":wsid}, verb="POST", body={"qlQuery": query } ) }}

2. Update variables

See also