How can I call an external rest api from within a generalPage module?

We are using confluence cloud.
We would like to populate a confluence page with data that is retrieved from an external site.

I tried the below

AP.request({
  url: 'https://services.mycompany.com/api/v1/products',
  type: 'GET',
  //data: {name: 'some text', description: 'test'}
  success: function(responseText){
    console.log(responseText);
  },
  error: function(xhr, statusText, errorThrown){
    console.log(arguments);
  }
});

but looking at the browser console, i see

GET https://dev-testcompany.atlassian.net/wikihttps://services.mycompany.com/api/v1/products 404 ()

It simply concatenated the our confluence cloud instance url with the url parameter in the request above.

How should I be getting external data from https://services.mycompany.com/api/v1/products ?

This one I can answer! Short story: You might not be able to, but it’s not Atlassian’s fault.

  • You don’t need to use AP.request(). You can simply use the feature of your browser – the XMLHttpRequest or jQuery’s wrapper if you have jQuery:
    $.ajax({url: '...'}).success(function(data) { ... }).
  • The REST call will work just fine, but the CORS specification says an iframe can’t reach out to another domain who doesn’t explicitly allow it. So, most probably, the REST answer will be “Request denied”, and that’s because of the browser/services.mycompany.com, not Atlassian.
  • Since you seem to own https:/services.mycompany.com, it may be possible to ask them to implement the solution: The solution to CORS is for the target domain to include the HTTP header:
    Access-Control-Allow-Origin: http://your-addon.mycompany.com – This way your browser will allow the request to be answered.

I see. Thank You.It seems we are just going to have a scheduled refresh of the main hbs file that shows in the iframe.