Confluence macro-id is always different in execute

Hi all,

I’m writing a plugin where I need to get the macro id of the macro being rendered. I followed the advice here: and this works on our test environment. However, on our dev environment the macro id I get on the page is different every time I load the page. In test, it’s always the same. Do you know why it would be different? We’re on Confluence version 6.13.4 in test and 6.15.2 in dev, but other than that the environments are the same.

Here’s the code. ReportManager just returns a string of content.


import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.spaces.Space;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.plugin.spring.scanner.annotation.imports.ConfluenceImport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ArticleCreationMacro implements Macro {
private static final Logger log = LoggerFactory.getLogger(ArticleCreationMacro.class);

private final PageManager pageManager;

private final SpaceManager spaceManager;

private final ReportManager reportManager;

public ArticleCreationMacro(PageManager pageManager, SpaceManager spaceManager, ReportManager reportManager) {
    this.pageManager = pageManager;
    this.spaceManager = spaceManager;
    this.reportManager = reportManager;

public String execute(Map<String, String> map, String string, ConversionContext conversionContext)
        throws MacroExecutionException {
    log.debug("executing article creation macro");
    try {
        MacroDefinition macroDefinition = (MacroDefinition) conversionContext.getProperty("macroDefinition");
        log.debug("loaded macro definition");
        log.debug("macro definition id: " + macroDefinition.getMacroId().get().getId());
        Page pageWhereMacroLives = pageManager.getPage(conversionContext.getEntity().getContentId().asLong());
        log.debug("page where macro lives: " + pageWhereMacroLives.getTitle());            
        Space space = CommonUtils.getSpaceFromParameterMap(map, pageWhereMacroLives, spaceManager);
        log.debug("space: " + space.getKey());
        ReportParameters reportParameters = new ReportParameters(ReportType.ARTICLE_CREATION, map, space,
                pageWhereMacroLives, macroDefinition);            
        return reportManager.getReport(reportParameters);
    } catch (Exception e) {
        log.error("error while executing article creation macro: ", e);
        throw new MacroExecutionException(e);

public BodyType getBodyType() {
    return BodyType.NONE;

public OutputType getOutputType() {
    return OutputType.BLOCK;



On What is the purpose of macro-id in the source XML? there is information on what I have found about the macro ID some time ago. Hope this helps …

It helps, but my understanding of the macro id is that once the page is saved, then the macro id shouldn’t change on subsequent page loads. If the page is edited, the macro id would change (of course), but that’s ok for my particular use.

I’m trying to find a way to uniquely identify a macro per page. However, the macro id is different every time the page loads, and none of the id’s being displayed by the log in my code (above) matches what the macro-id is in the storage.

For example, when I use “View Storage Format” of the page, I get this:

<p><ac:structured-macro ac:name="article-creation-macro" ac:schema-version="1" ac:macro-id="ed2dba3b-2913-4b1b-b9f5-ca9fce236d19" /></p>
<h2>Article Usage</h2>
<p><ac:structured-macro ac:name="article-usage-macro" ac:schema-version="1" ac:macro-id="00e842bc-3987-4c42-8af4-690381325ea8" /></p>

But my log has this (I removed the extra lines for clarity):
2019-05-13 11:26:11,933 DEBUG [http-nio-8090-exec-10] [] execute macro definition id: 5985cd29-7202-40eb-a2b8-c1bf566eb68c

Is there a better way to get the actual macro-id?

@collene.hansen I realise this is a very old thread, but did you resolve this issue? I am suffering the same and cannot work out what has went wrong. In my situation, I have a prod and test instance both now at 6.14.2. As with you, it works on the test instance. But unlike you, mines also used to work on the prod instance. At some point and for some reason it has stopped working and generates a new uuid on every reload even though the storage format macro id remains the same. The test instance still works correctly.

It’s driving me round the bend >:[

Facing the same issue… getting new macro id on every macro render (storage format remains the same, but macro id in a rendering context changes)

weird stuff, anyone has found the solution or the cause?