If I run the following script from JIRA it work:
$.ajax({ url : "http://localhost:8080/jira/rest/api/2/project", type : "GET", dataType : "json", contentType : "application/json", success : function(response) { console.log(response); }, error : function(jqXHR, textStatus, errorThrown) { console.log(textStatus + " : " + errorThrown); } });
...however if I run it from Confluence it doesn't work. The error function gets "error" for the textStatus and nothing for errorThrown.
I have a Trusted Application link setup between JIRA and Confluence.
Is it possible or not possible to do this via JavaScript?
Community moderators have prevented the ability to post new answers.
It is not possible to do this in JavaScript due to your browser's security policy (see http://en.wikipedia.org/wiki/Same_origin_policy). If you have root access on your JIRA server, you may be able to work around this by configuring your JIRA server's Cross-Origin Resource Sharing (CORS) Policy - this answer has some instructions on how you can attempt it: https://answers.atlassian.com/questions/69356/cross-origin-resource-sharing-with-jira-rest-api-and-javascript
Alternatively you can build a Java plugin that runs on your Confluence server to make the JIRA REST calls, and then your JavaScript can call a custom REST resource supplied by your Confluence plugin to retrieve the information from JIRA.
I suspected something like that was the case. Thanks for the confirmation.
I had already started doing option 2 before I posted this... so I'll just stick with that method.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this!
Works for me in my local development system: localhost:8090 and localhost:8080
var jira = [];
var projects = [];
var request = $.ajax({
url: "/rest/jiraanywhere/1.0/servers",
type: "GET",
async: false,
dataType: "json"
});
request.done(function( msg ) {
$.each( msg , function( key, val ) {
if(val.name && val.name.contains('JIRA')){
jira.push(val);
return true;
}
});
});
request.fail(function( jqXHR, textStatus ) {
console.log( "Request1 failed: " + textStatus );
});
if(jira.length > 0){
var requestProjects = $.ajax({
url: "/plugins/servlet/applinks/proxy?appId="+jira[0].id+"&path="+jira[0].url+"/rest/api/2/project",
type: "GET",
async: false,
dataType: "json"
});
requestProjects.done(function( msg ) {
$.each( msg , function( key, val ) {
if(val.name){
projects.push(val);
}
});
});
requestProjects.fail(function( jqXHR, textStatus ) {
console.log( "Request2 failed: " + textStatus );
});
}
console.log( "projects: " + projects.length );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi kai,
I am in exactly the same dilemma, I have a confluence blueprint that i am trying to get all JIRA projects in a dropdown but it is not working. I have tried implementing your code above and tied the projects array to the dropdown but it is not working. I cannot see any console logs at all. My code is:
$(document).ready(function() {
$(".project").select2({
data: projects
});
});
Any ideas?
thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chris,
did you have any luck with getting all JIRA projects list in your confluence blueprint?
thanks,
Sandra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sandra,
I finally managed to get it working using Kai's method but also using the Confluence.getContextpath().
Kind regards,
chris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Chris,
how did you manage the authorization step? when I try to access a JIRA api via the application link path I always get a unauthorized exception even tough I use the same admin account on both instances? do you add the current logged in user to the request call? how do you get the current user? Please help me
Best regards,
Tom
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm not sure if you really can do this via JavaScript, but Confluence already has a macro for querying JIRA projects. It's enabled by default when creating an application link from JIRA to Confluence.
Best regards,
Lucas Timm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Is there any AJAX call that I can use to get all the teams the current logged in user belongs to?
Thank You,
Asif
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can I do same for onDemand? I need to be able to query the weblinks of a JIRA issue as weblinks don't showup in issue navigator
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to the response I got from Atlassian on ticket https://ecosystem.atlassian.net/browse/AC-2129, this is still not supported in Cloud. They pointed me to this feature request:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.