Hi @dmorrow
My understanding is that the intention of the Confluence page preview feature is to provide users with a visualization of the page prior to publishing it.
Yes, exactly, I agree! Users want to see an accurate preview before publishing. This is not possible at the moment. Please have a look at the url
parameter section of the dynamicContentMacro page..
About halfway in the paragraph it states:
Preview Mode: If you use the {macro.id}
in your URL, the REST api will not return the macro body during a preview request, because the page has not been saved yet. You can use the {output.type}
parameter to detect whether the macro is rendered in preview mode and adapt the response accordingly.
In order to receive the body of a macro, the rest API needs to be called like this:
"/rest/api/content/" + pageId +"/history/" + pageVersion +"/macro/id/" + macroId,
Please note that there’s a macroId at the end, which is absolutely required to fetch the body from the Confluence API. Before the page is saved, there either is no macroId OR the macroId is stale and belongs to an old version of the macro (if it has been updated). In either scenario, the API responds with an error.
For our macro there is no way to determine whether it’s currently in preview mode or not, because Confluence tells it that there the current mode is “display”. The provided macro- and pageIds however lead to an error in this mode when being sent to the API. And we can not know if this is due to it being in preview mode or something else is going wrong, because Confluence does not give us any hints about this, thus we have to display an error to the user, which is VERY confusing to them, and I can’t blame them.
The documentation of dynamicContentMacro is even aware of this! Again, I want to quote it:
If you use the {macro.id}
in your URL, the REST api will not return the macro body during a preview request, because the page has not been saved yet. You can use the {output.type}
parameter to detect whether the macro is rendered in preview mode and adapt the response accordingly.
It clearly says that we can use the output.type
to work around this case, but this is just inaccurate information. This is becoming increasingly frustrating because we get more and more requests from users who do not understand this error.