Access JIRA REST API from Confluence User Macro

Louise Kasemeier August 4, 2015

Hi Atlassian Experts

I'm trying to create a user macro that can access the JIRA REST API to pull issues into Confluence so I can make attractive report pages. In general I find that the JIRA issues macro and built in reports don't meet my needs. I've been successful at consuming our internal REST APIs in Confluence Macros but I can't seem to make it work with JIRA.

  • JIRA and Confluence are linked via Application Links using OAuth
  • Confluence is whitelisted in JIRA

I'm logged into both applications but I get a 401 Unauthorised error when I try to retrieve an issue.

I'd like to use OAUTH in preference to Basic Auth but i don't know much about it. The tutorial page on authenticating via OAUTH was a little over my head. I suppose my confusion lies in the fact that I assumed setting up the link was taking care of the 'OAUTH dance' piece so why would I need to (re?)implement so much functionality to make it work from Confluence?

Thanks in advance for any suggestions!

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2015

Hi Louise,

I recently coded retrieving data from Confluence in JIRA plugin which is pretty the same. I see that classes are not tied to JIRA packages so the the code snippet should work for you:

public static String doStuff(ApplicationLink appLink) {
    String error = "";
    ApplicationLinkRequest applicationLinkRequest = null;
    ApplicationLinkRequestFactory applicationLinkRequestFactory = appLink .createAuthenticatedRequestFactory();
    try {
      applicationLinkRequest = applicationLinkRequestFactory.createRequest(
              com.atlassian.sal.api.net.Request.MethodType.POST, YOUR_URL);
      applicationLinkRequest.addRequestParameters("param1", VAL_1, "param2", VAL_2);
      applicationLinkRequest.setFollowRedirects(false); // true be default
      ResponseHandler<Response> responseHandler = new YourCustomResponseHandler<Response>();
      // Parse your response in "handle" method of your ResponseHandler implementation
      applicationLinkRequest.execute(responseHandler);
    } catch (CredentialsRequiredException e) {
      error = "Failed, problem with Application Link: " + e.getMessage();
      log.error("Failed, problem with Application Link", e);
    } catch (Exception e) {
      error = "Failed: " + e.getMessage();
      log.error("Failed", e);
    }
    return error;
  }
Louise Kasemeier August 5, 2015

Hi there

Thanks for your response! I was hoping for a client-side (jquery/ajax) solution though.

We may look into a plugin but I'd really like to do this in a user macro if that's possible. Or maybe there's some reason I shouldn't be doing that? smile

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2015

I do not think it's possible, but to be sure, please post a new question asking if you can reuse configured ApplicationLink via JavaScript to make REST call from Confluence page to JIRA. Maybe someone knows it for sure.

TAGS
AUG Leaders

Atlassian Community Events