Unable to use Connect JavaScript API inside macro editor

I have a full screen editor and it seems the window.AP.XX is not working there. Here is my html file for the editor

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="https://connect-cdn.atl-paas.net/all.js"></script>
</head>
<body>
<script type="text/javascript">

    window.AP.context.getContext(resp => {
        console.log('Context', resp)
    });

    window.AP.confluence.getMacroData(data => {
        console.log('Macro Data', data)
    });

    AP.context.getToken(function(token){
        console.log("JWT token string", token);
    });

    AP.user.getCurrentUser(function(user) {
        console.log("The Atlassian Account ", user);
    });

    window.AP.require(["confluence", "dialog"], function (confluence, dialog) {
        confluence.getMacroData(data => {
            console.log('Macro Data', data)
        });
    });
</script>
</body>
</html>

I get the callback for only the first call ( window.AP.context.getContext ) but the resp is empty object i.e. { }

I do not get any callback for other calls.

These APIs are working fine in viewer though. Only editor has issues.

How am I supposed to use window.AP in the editor iframe?

1 Like

What does window.AP look like?

If you do

const { context, confluence, user } = window.AP;

are they populated?

Does this mean you are creating your own nested iframe inside your Connect app iframe? If so, loading the all.js library in that nested iframe won’t work without taking extra measures.

I believe Atlassian is using their simple-xdm library to implement AP / all.js functionality. You could either look into setting that up for your nested iframe as well or use other means of communication between your nested iframe and parent iframe, and have your parent iframe delegate calls to AP.

Hope this helps!

Cheers,
Sven

@david, yes these variables are populated but calling functions on them do not do the callback as I have described above

@SvenSchatter, I am not doing iframe inside an iframe. The HTML I posted above is what loaded in the editor iframe

Actually not getting callback for other function call is inconsistent. Sometime I get callback and sometime not.

I am consistently get callback for getContext but with empty response i.e. {}. I am blocked without the context object

After some experiment, I am coming to this conclusion

  • AP.context.getContext always returns empty object inside custom macro editor. It seems the getContext is not supported inside custom macro editor.
  • If you call multiple atlassian APIs in parallel from connect JavaScript library then you many not receive the callback for some of the APIs. However if you call them serially then your callbacks get called always. In the above example, if I chain the API calls then I get the callbacks always but when done in the parallel (as in my first post in this thread) then randomly some of the callbacks are not called back.

@ibuchanan
I would like someone from Atlassian to confirm this behavior as expected behavior. I do not find these anywhere in the documentation.