What I tried was:
## Macro title: totalBugs
## Macro has a body: Y
## Body processing: Rendered
## Output: Rendered
##
## Developed by: Margus Martsepp
## Date created: 06/02/2023
## Installed by: Margus Martsepp
## @param Search1:title=Search1|type=string|required=true|desc=Choose search 1
## @param Search2:title=Search2|type=string|required=true|desc=Choose search 2
#set($jiraUrl = "https://.../")
#set($proxyHost = "http://...")
#set($proxyPort = "8080")
#set($action = $helper.getActionContext())
#set($jira = $action.getApplicationContext().getComponent("jira"))
#if($jira)
#error("Jira variable is not initialized, check if the Jira plugin is properly installed and configured")
#end
#set($result1 = $jira.search($paramSearch1, $jiraUrl, $proxyHost, $proxyPort))
#set($result2 = $jira.search($paramSearch2, $jiraUrl, $proxyHost, $proxyPort))
#if($result1)
#error("Search 1 has returned no results, check the query and connection details")
#end
#if($result2)
#error("Search 2 has returned no results, check the query and connection details")
#end
#if($result1.total == 0)
#error("Search 1 has returned no results, division by zero is not possible")
#end
#if($result2.total == 0)
#error("Search 2 has returned no results, division by zero is not possible")
#end
#set($count1 = $result1.total)
#set($count2 = $result2.total)
#if($count2 == 0)
#error("Search 2 has returned no results, division by zero is not possible")
#end
#set($result = $count1 / $count2 * 100)
#set($output = "Result of dividing search 1 count ($count1) by search 2 count ($count2) is: $result")
$output
Similarly to this I tried getIssuesFromJqlSearch ex:$jira.getIssuesFromJqlSearch($paramSearch1, 1000))
but in both cases this yielded to:
Result of dividing search 1 count ($count1) by search 2 count ($count2) is: $result
Is there something that I forgot to configure for the JIRA service or is the API used in a different way?
It turns out this is next to impossible with VTL templates alone. However, by using JavaScript it is as simple as making an Rx observable request. The complication here is that if Jira and Confluence are on different servers or URLs, it is a CORS request. I already had OpenId referrals set up, but I had to modify the configuration to enable CORS and restart the application.