---
title: "JMWE Cloud: How to query the Assets API using Nunjucks"
canonical: "https://support.appfire.com/space/SUPPORT/385744938/JMWE%20Cloud%3A%20How%20to%20query%20the%20Assets%20API%20using%20Nunjucks"
format: markdown
---
## 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](https://api.atlassian.com) (`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 [https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/).
- **Assets Workspace ID:**
  - Open your browser and navigate to: `https://<yourinstance>.atlassian.net/rest/servicedeskapi/assets/workspace`
  - 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](https://support.appfire.com/space/JMWEC/466289991/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

- **email**: Enter the user email associated with the API token.
- **token**: Enter the API token you generated.
- **wsid**: Enter the Workspace ID obtained in the prerequisites.
- **query**: Enter your AQL string. See[https://support.atlassian.com/jira-service-management-cloud/docs/use-jira-and-assets-query-languages-with-assets/](https://support.atlassian.com/jira-service-management-cloud/docs/use-jira-and-assets-query-languages-with-assets/) for more information on using AQL.
  - *Example:* `Key IN ('XX-01')` searches for a specific asset key.

## See also

- [https://support.atlassian.com/jira-service-management-cloud/docs/use-jira-and-assets-query-languages-with-assets/](https://support.atlassian.com/jira-service-management-cloud/docs/use-jira-and-assets-query-languages-with-assets/)
- [https://developer.atlassian.com/cloud/assets/rest/api-group-object/#api-object-aql-post](https://developer.atlassian.com/cloud/assets/rest/api-group-object/#api-object-aql-post)
- <u>[JMWE Documentation: callRest filter](https://appfire.atlassian.net/wiki/spaces/JMWEC/pages/createpage.action?spaceKey=JMWEC&title=Build-your-own%20%28scripted%29%20Post-function)</u>