Cacheable macro parameters

atlassian-connect-dev
confluence-cloud
atlassian-connect-express

#1

I’m trying to make a dynamic macro to be cacheable.
How do I get the macro parameters?

Before I was getting the macro parameters from the url, but now I can’t. The only way I found is to use the REST call ‘Get macro body by macro ID’
Using this approach creates an error in preview mode of the macro (in view mode everything works fine), because macroId parameter is not defined.


Cacheable macro
#2

Hi @arosati,

Thanks for posting this in the community.

I’m not sure of Confluence, but I’ll tap the right person here.

AFAIK, for cacheable app iframes, you may get the context parameters thru: https://developer.atlassian.com/cloud/jira/platform/cacheable-app-iframes/#getting-context

That is:

AP.context.getContext(function(context) {
  alert('The current project key is ' + context.jira.project.key);
});

You may find more information here: Building fast loading apps with new Connect APIs, which features cacheable iframes during Atlas Camp.

Cheers,
Anne Calantog


#3

hi @acalantog,

Context parameters don’t contain macro parameters. From the context I’m able to get content.id, content.version and the macro.id:

const pageId = context.confluence.content.id;
const pageVersion = context.confluence.content.version;
const macroId = context.confluence.macro.id;

With these variables then I’m able to call ‘Get macro body by macro ID’ REST API to get macro parameters.
This approach works in view mode, but it is causing an error in preview mode in the macro editor because the variable macro.id is not defined.

Cheers,
Andrea


#4

@arosati, we identified this as a gap a while back. We initially intend to support the existing API AP.confluence.getMacroData() in view mode (ACJS-1025), not only in edit mode. I will make a note on that ticket to make sure we support preview mode as well.


#5

hi @epehrson,

so for now there are no work arounds to make the macro working in preview mode?

Thanks,
Andrea


#6

@arosati, I don’t think so. Not even after saving the page does the macro ID seem to be present in the context when in preview mode.


#7

@arosati Can you share the exact error that you get when you try for the Preview mode?


#8

@arosati Can you also confirm if you are talking about macro previews or the entire page(or content) preview?


#9

@arosati I think AP.confluence.getMacroData only works with custom macro editor. For default editor you can get parameters from URL, for example:

            {
                "key": "macro",
                "name": {
                    "value": "macro"
                },
                "url": "/render?parameter={parameter_key}",
                "bodyType": "rich-text",
                "outputType": "block",
                "parameters": [
                    {
                        "identifier": "parameter_key",
                        "name": {
                            "value": "value"
                        },
                        "type": "string"
                    }
                ]
            },

#10

hi,

@akashyap, I see that is not working in both cases.
In a single macro preview I see the error:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>404</status-code><message>null for uri: https://srtest9.atlassian.net/wiki/rest/api/content/249266188/history/1/macro/id/?_r=1539855248258</message></status>

As you can see from the error the macro id is not specified, because I think the macro id is still not available.

In the new editor (from a blogpost) when I load the blogpost in edit more I see this error:

{"statusCode":404,"data":{"authorized":false,"valid":true,"errors":[],"successful":false},"message":"No macro found on content id : ContentId{id=249266188} with version: 1 and macroId: 2310e8a2-91d9-4c17-862d-162df7c2122f"}

Here the macro id is specified, but still getting an error.

@rading, I cannot use the parameters from the URL because I’m using a cacheable macro.


#11

Hi @epehrson ,

Is it still in the plans to support cachable iframes for macros? They say they support it but if macros can’t access their macro parameters, usecases are extremely limited.

Our usecase is for customers with lists of requirements: They annotate each item, which means they could have hundreds of requirements per page. If our macros are cached by the browser, displaying them is instant. If not, the browser limits to 6 concurrent requests per page, so it takes a lot of time to display many macros.

Thank you very much,
Adrien


#12

Hey Adrien,

I had the chance to talk to someone from the Confluence Cloud Ecosystem at the Atlassian Summit, because we have the same issue. He told me that accessing the macro properties will be available soon.

Best,
Timur