Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

User Macro fails with Ajax call to JIRA

Prototyping a plugin using User macros.

As a newbie in js I'm struggling with understanding the escaping of URL:s.

From the following post I get that the Ajax call expects "No quotes":

type: "GET",
contentType: "application/json",
  success: function(msg){


When experimenting with a call with a JQL with example below:

It works as long as I have an JQL that does nott contain any space or quotes. 

For generic JQL:s I've attempted using "encodeURIComponent" or "encodeURI" - the REST call fails in the Ajax call, but works fine in a browser. I don't understand why?

Also tried with hardcoded "paths" with %20, %22 and so on, they alos work OK in broowser or command line, but fails in the USer Macro.


  type: "GET",
  url: "<Confluence URL>/plugins/servlet/applinks/proxy?appId=<UUID>&path=<JIRA URL>/rest/api/latest/search/jql=<YOUR_JQL>",
  dataType: "json",
  async: false,
  success: function( data ) {
      //process data and render it in html tags


Another example attempting to get the Sum Story points printed from a JQL.

The path looks OK in console in browser, but fails in Ajax call! And Ok in browser


theurl = "/rest/scriptrunner-jira/latest/jqlfunctions/aggregateResult?jql=" + "$paramJql" + " AND issueFunction in aggregateExpression(\"Totalpoints\", \"storyPoints.sum()\")"
// theurl = "/rest/scriptrunner-jira/latest/jqlfunctions/aggregateResult?jql=" + "$paramJql" + " AND issueFunction in aggregateExpression(\"Totalpoints\", \"storyPoints.sum()\")"
// theurl = '/rest/scriptrunner-jira/latest/jqlfunctions/aggregateResult?jql=' + encodeURIComponent("$paramJql" + ' AND issueFunction in aggregateExpression("Totalpoints", "storyPoints.sum()")')
console.log( "theurl: " + theurl);

type: "GET",
url: "<UUID>&path=" + theurl,
dataType: "json",
async: false}).done(function (response) {

var txt3 = document.createElement("p"); // Create with DOM
var divContainer = document.getElementById("showJira");

one = response.Totalpoints;
txt3.innerHTML = txt3.innerHTML + "Total StoryPoints: " + one;
divContainer.innerHTML = "";
console.log( "Total StoryPoints: " + one);
console.log( "response: " + response);

divContainer.innerHTML = "";

The Ajax call returns with null.

2 answers

1 accepted

0 votes
Answer accepted

Hi @zaphnet ,

Sorry for delay on getting back to you.

After running some tests, please find below an example on how to build the AJAX request.  For this to work you must have an Application Link between Jira and Confluence working.

If the Application Link is configured with OAuth only, you must Allow the user in Confluence performing the action to perform Actions with Jira, the famous "Login & Approve".

## Macro title: My Jira Search Macro
## Macro has a body: Y
## Body processing: Rendered
## Output: No Output
## Developed by: Rafael Pinto Sperafico
## Date created: 04/09/2019
## Installed by: Rafael Pinto Sperafico

## User Macro to search in Jira
## @noparams

<script type="text/javascript">
AJS.toInit(function() {

// JQL: jql=project=QWERTY
// url: AJS.Confluence.getBaseUrl() + '/plugins/servlet/applinks/proxy?appId=' + + '&path=' + applicationLink.rpcUrl + encodeURI('/rest/api/2/search?jql=project=QWERTY'),

// JQL: jql=project="Basic Software Development"
// url: AJS.Confluence.getBaseUrl() + '/plugins/servlet/applinks/proxy?appId=' + + '&path=' + applicationLink.rpcUrl + encodeURI('/rest/api/2/search?jql=project%3D%22Basic%20Software%20Development%22'),

// JQL: jql=issueFunction in aggregateExpression(total,"originalEstimate.sum()")
// url: AJS.Confluence.getBaseUrl() + '/plugins/servlet/applinks/proxy?appId=' + + '&path=' + applicationLink.rpcUrl + encodeURI('/rest/scriptrunner-jira/latest/jqlfunctions/aggregateResult?jql=issueFunction%20in%20aggregateExpression(total%2C%22originalEstimate.sum()%22)'),

var search = function(applicationLink) {
url: AJS.Confluence.getBaseUrl() + '/plugins/servlet/applinks/proxy?appId=' + + '&path=' + applicationLink.rpcUrl + encodeURI('/rest/api/2/search?jql=project%3D%22Basic%20Software%20Development%22'),
type: "GET",
contentType: "application/json",
success: function(data) {
.done(function(data) {

// Get a list of all application link configured in Confluence
url: AJS.Confluence.getBaseUrl() + '/rest/applinks/1.0/listApplicationlinks.json',
type: "GET",
dataType: "json",
success: function(data) {
.done(function(data) {
// Iterate over a list of application links
// search for Jira application link
// search in Jira application link found
jQuery.each(data.list, function(i, v) {
if (v.application.typeId == 'jira') {

Tested on Confluence 6.6.7 and 6.15.2

Kind regards,

Thanks for your help!

Finally got some time to review all my posts/attempts.

The call to get proxy and jira server failed due to websudo, but those were never the problem.

I must have made some other typo in combination with the final working url:

var theurl = encodeURI(confbase + "/plugins/servlet/applinks/proxy?appId=" + confproxy +"&path=" + jirabase + "/rest/scriptrunner-jira/latest/jqlfunctions/aggregateResult?jql=" + encodeURIComponent('fixversion="$paramProjectIssue" AND issueFunction in aggregateExpression("Totalpoints", "storyPoints.sum()")'));


Finally got all the "" and '' to work with $paramProjectIssue parameter from Built In Macro.


I'm trying to do something similar to Zaphnet and currently am running into error 500.


I'm using HTML macro from Confluence and trying to do some JQL query to JIRA.

I've followed the steps where you get the Jira UUID and the do the JQL query but in vain.

My query looks something like this


And if I try this directly from a web page I still get 500 error.

Any thought? 



0 votes

Hi @zaphnet ,

I usually perform the JQL search in Jira first, e.g:

text ~ "sample feature" and project = "Basic Software Development"

This is result in the following encoding in my web browser address bar:


Then, I copy the JQL above and paste it into the AJAX call surrounding it with single-quotes ('):

url: 'http://localhost:8080/jira/rest/api/2/search?jql=text%20~%20"sample%20feature"%20and%20project%20%3D%20"Basic%20Software%20Development"',
type: "GET",
dataType: "json",
success: function(data) {

Hope the above helps.

Kind regards,

Hi @zaphnet ,

Sorry, it took me some time to understand from your description that you are actually attempting on calling ScriptRunner REST API endpoint (from Adaptavist) to get the Sum Story points.

When running aggregateExpression from Adaptavist, the search request to be used is as you have mentioned:

# Adaptavist REST API

and not:


Just to be sure we are on the same page ;)

For testing purposes, could you please replace the endpoint with:

aurl = 'CONFLUENCE_BASE_URL/plugins/servlet/applinks/proxy?appId=<JIRA_UID>&path=JIRA_BASE_URL/rest/api/2/issue/STP-207';

The testing purpose is to validate the request. You should get a STP-207 Jira Issue (

At the same time, would be possible to share your project somehow (e.g repository) so I could run some tests and get back to you with a resolution?

Kind regards,

Sorry for the confusion I've been having the same problem with both sql and script runner REST api:s.

The calls

aurl = 'CONFLUENCE_BASE_URL/plugins/servlet/applinks/proxy?appId=<JIRA_UID>&path=JIRA_BASE_URL/rest/api/2/issue/STP-207';


aurl = 'CONFLUENCE_BASE_URL/plugins/servlet/applinks/proxy?appId=<JIRA_UID>&path=/rest/api/2/issue/STP-207';

both work fine.

Still confusing to me how to write the url, some experiments in a browser (GurkaFilter a public example filter):


Works fine, now attempting with another filter using the filter number.


Works fine, now attempting to use its name("Gurka Filter"):

None of below works

filter="Gurka Filter"





Thanks for all the help, the problems that I encounter is in the combination of the application link/proxy and jira rest api.

Example above accessing jira rest api directly works fine


Hi @zaphnet ,

Thank you for your update and examples.

Could you please try removing the quotes from your JQL search, e.g:


Kind regards,

Still fails


Works fine.


Attempted another workaround: Directly in jira rest api:


Works OK with output:


With a filter JQL: GurkaFilter

GurkaFilter=issuekey = STP-207 AND issueFunction in aggregateExpression(Totalpoints, "storyPoints.sum()") 


Fails with 

{"message":"Negative array index [-1] too large for array size 0"}


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Confluence Cloud

Please tell us how you use Confluence space settings

👋 Hi there, a few of us at Atlassian would love to learn about how you use "space settings" functionality in Confluence. A facelift to the space settings is long overdue and we want to start with im...

567 views 15 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you