Is it possible to use AP request via an iframe in a Jira server addon?

To factorize the code between our Jira server addon and our Jira cloud addon, I used to provide IHM via an iframe in jira server addon like for jira cloud addon. It’s working very much. But this time, I need to use AP request and I didn’t find documentation to do that.

Is it possible to use AP request via an iframe in a Jira server addon? It would be very useful.

2 Likes

Unfortunately no. AP.request relies on the connect plugin being installed. The connect plugin only works in JIRA cloud.

You could replicate something similar. AP.request is just a wrapper around some cross domain ajax. If your iframe is on the same domain as the jira server instance you could do something like:

function crossDomainAjax(params, callback) {
  if(AP && AP.request) {
   // i'm using connect
   AP.request(params, callback);
  } else {
    window.parent.jQuery.ajax(params).done(callback);
  }
}
3 Likes

Thanks for your answer. I tried it but my iframe is not on the same domain as the jira server instance.
I tried to enable CORS requests with the whitelist as describe here: https://confluence.atlassian.com/adminjiraserver073/configuring-the-whitelist-861254007.html

But I obtain the error: XMLHttpRequest cannot load http://localhost:2990/jira/rest/api/2/project/P1. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

Is it possible that doesn’t work because I use atlas-run command to run Jira?

I think localhost is a special case. You might want to try using something like ngrok to replace it with a real domain.

1 Like

Thanks, the problem came from the Jira version, The withelist works only from version 7.0. Thanks again