Rendering macros within another macro


I’m in the process of creating a dynamic macro for Confluence. Macros within my macro does not work properly and it seems to be due to the fact that pageId, pageVersion etc. is missing in the request of the embedded macro - ...?pageId=&pageVersion=&pageTitle=&....

Currently I’m using the Confluence Cloud REST API and /rest/api/content/{id}/history/{version}/macro/id/{macroId} to fetch the macro body and then /rest/api/contentbody/convert/{to} to convert it to ‘view’. I thought it was reasonable that the contentIdContext in the convert request would provide the necessary data, but that didn’t make any difference for me.

My two questions are:

  1. How do I make Confluence data such as pageId accessible to macros within my macro?
  2. What is the purpose of the contentIdContext and the spaceKeyContext parameters in the convert request?
1 Like

Hi @julia

You should be able to render a nested macro without needing to convert the macro body as it’s provided in HTML.

Some example code I use to render only the nested macro, and nothing else:

      url: '/rest/api/content/{{pageId}}/history/{{pageVersion}}/macro/id/{{macroId}}',
      success: function(responseText) {
        document.body.innerHTML = JSON.parse(responseText).body;

When I did this all URL context parameters were supplied for the child macro.