Hi,
I'm in Confluence. From Javascript, I'd like to get the list of project keys from JIRA. I have an Applink between the two instances, but I don't have administrative permissions on JIRA, so I can't use OAuth. However, the JIRA projects are public.
From Javascript, is it possible to call the REST resources of JIRA?
I'm getting the CORS issue "Origin http://...mymachine... is not allowed by Access-Control-Allow-Origin." Is there any way to get the list of JIRA projects in Confluence?
Thanks
Community moderators have prevented the ability to post new answers.
Found it!
Example:
# Query all applinks: http://localhost:1990/confluence/rest/applinks/1.0/applicationlink/type/jira # Answer: <applicationLinks> <link rel="self" href="http://localhost:1990/confluence/rest/applinks/1.0/applicationlink/144880e9-a353-312f-9412-ed028e8166fa"/> <id>144880e9-a353-312f-9412-ed028e8166fa</id> <typeId>jira</typeId> <name>Atlassian JIRA</name> <displayUrl>https://jira.atlassian.com</displayUrl> <iconUrl>http://localhost:1990/confluence/.../16jira.png</iconUrl> <rpcUrl>https://jira.atlassian.com</rpcUrl> <isPrimary>false</isPrimary> <isSystem>false</isSystem> </applicationLinks> # Then take the applink ID and get all applink'ed entities: http://.../confluence/rest/applinks/1.0/entities/144880e9-a353-312f-9412-ed028e8166fa # Result: <entities> <entity iconUrl="http://localhost:1990/confluence/.../16jira.project.png" typeId="jira.project" name="[CLOSED] Clover Maven2Plugin" key="CLMVN"/> <entity iconUrl="http://localhost:1990/confluence/.../16jira.project.png" typeId="jira.project" name="A Test Project" key="TST"/> ...
Source: I just went to the sources of Applinks... https://bitbucket.org/atlassian/application-links/src/applinks-parent-3.10.6/applinks-plugin/src/main/java/com/atlassian/applinks/core/rest/EntityResource.java?at=applinks-parent-3.10.6
Interesting find. How do you connect to JIRA from within a Confluence onDemand iframe? AP.request() always prepends the on-demand host url. So in this example - even though you can query the confluence applinks REST API, how do you send queries to JIRA from within the Confluence remote app iframe?
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.
Can someone give me advice on passing the cookie or authentication when doing the REST call Adrien mentioned to get the list of JIRA projects?
For some reason one call to a particular JIRA instance works and gives me a list of projects (not sure if it's all the projects or just the ones available to anonymous access), but another call to a different JIRA instance gives me a 401 error. Maybe it's a configuration issue but I'm not too familiar with application linking.
I went here for advice: https://developer.atlassian.com/display/DOCS/REST+and+os_authType
But adding os_authType to the REST URL doesn't seem to help.
function getJiraProjects(applicationId){ var restUrl = AJS.contextPath() + "/rest/applinks/1.0/entities/"+applicationId+"?os_authType=any"; $('#select-example') .find('option') .remove() .end(); console.log(restUrl); $.ajax({ type: 'GET', url: restUrl, data: { key: "value" }, dataType: "xml", success: function (xml){ console.log('Found jira projects successfully for '+applicationId); jiraProjectKeys = []; $(xml).find("entity").each(function() { $('#select-example') .append($('<option>', { value : name }) .text($(this).attr("key"))); //console.log('appending '+$(this).attr("key")+' to #select-example'); jiraProjectKeys.push($(this).attr("key")); }); console.log('jiraKeys = '+ jiraProjectKeys); }, xhrFields: { withCredentials: true }, crossDomain: true, error: function(xhr, status, error) { console.log('error getting jira projects for application id '+ applicationId + ' '+xhr + ' ' + status); } }); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok I found out why I was getting the 401 error. Me as a user had to set up the authentication within that particular app link b/w JIRA and Confluence which hadn't been done yet. So now everything works for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello @Jason Nguyen and thank you for your code. some parts of the solution are not working the way it should and perhaps you can help me with that. i have linked the confluence and jira test servers successfully with each other. 1) if i am logged as admin i get without any problems the id of jira BUT if i am normal user i get 401 ERROR "this resource requires admin rights" 2) if i have the ID and i am requesting for the JIRA Projects i get 401 ERROR "Authentication Required" BUT if i dont use any ID i get all the projects from confluence but not from jira (without authentication) to solve the second part i have tried some basic authentication methods in ajax but it didnt work. is it possible that the problem lies in my confluence developer version which is connected to a copy of the original jira server? thanks in advance and merry xmas and a happy new year
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check this it may help you
https://developer.atlassian.com/static/rest/jira/6.0.1.html#id141644
something you need to try like this
$.ajax({ url : "http://localhost:8080/jira/rest/api/2/project", type : "GET", dataType : "json", contentType : "application/json", success : function(response) { console.log(response); } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's right, but that's when I get the CORS issue "...is not allowed by Access-Control-Allow-Origin". We can't perform a REST request when the JIRA server is on another domain, unless the JIRA server allows it. It is probably possible to make JIRA allow it, but I don't know how yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've also tried Radu's suggestion of installing apache http in front of JIRA and have yet to figure out how to get aroudn the CORS issue when calling the JIRA REST api from Confluence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you're facing a config issue, rather than a programming one ...
The only way to do it (that I know of) is to install apache httpd in front of JIRA and:
Header add Access-Control-Allow-Origin "http://my.domain1.com" Header add Access-Control-Allow-Origin "http://my.domain2.com"
HTH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That would work, but I'm using OnDemand.
I'm like "There must be a (programming) way... Somebody must have faced the usecase before!"
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.
No, I just used the answer above where the Applink returns the list of JIRA projects. I can't call other REST apis of JIRA.
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.