Accessing REST API from ACE

martin February 27, 2015

I am trying to access the Confluence REST API from my Backbone application on an Atlassian Connect Express server. I get my application up and running but when I try to fetch data from the REST API I get the following error message: 

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://localhost:1990') does not match the recipient window's origin ('http://localhost:3000').

My guess is that this is by design of the browser since accessing a JIRA resource on my 1990-port from the site on port 3000 is not allowed? Do I have to configure this configuration in the atlassian-connect.json or how does it work? Do I really have to use the modules provided that renders my app as an iframe (I use the webItem module at the moment)?

All help is greatly appreciated.

 

Cheers!

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Travis Smith
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.
February 27, 2015

Since your Connect app runs inside an iframe, a normal AJAX request is cross domain and likely the source of your error. If you instead use AP.request to make the request, it will be bridged across to the host product and not be a cross domain request. 

It doesn't matter what or where the content is in the Atlassian Connect app, as all in production content is rendered in an iframe within Confluence. 

martin February 27, 2015

Thanks for your swift answer Travis! I do use AP.request, i override my Backbone.sync with something like this: AP.require('request', function(request){ request ({ url: '...', //..., success: function() { ... } }); }); I'd expect that to produce the same result right? By the way, my app is not running inside an iframe at the moment, I use the webItem module to produce a link to my app in the top-bar. I'm starting to suspect this is the wrong way of doing it...

Travis Smith
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.
February 27, 2015

Yeah, if you have a link to your add-on that doesn't exist as an iframe, you'll need to proxy all the calls through the backend (ACE) to Confluence rather than doing direct calls to the product. This explains the postMessage complaint. Nothing AP will work without the iframe since it makes a call to the parent frame (and there isn't one).

martin February 27, 2015

Yeah, kind of hard calling the parent frame then! :) I guess I'm missing something obvious here but I have tried to google for some tips on how to do the proxy via backend, could you please give me a hint? As an alternative, is it possible to render my add-on in a full screen iframe inside of confluence, i.e covering the whole browser window with an iframe containing my stuff?

Travis Smith
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.
February 27, 2015

You should be able to create a dialog that's 100% high/wide: https://developer.atlassian.com/static/connect/docs/javascript/module-Dialog.html. You might want to use 100vh instead of 100% for height though.

martin February 27, 2015

Thanks mate, much appreciated!

TAGS
AUG Leaders

Atlassian Community Events