How do you retrieve a macro's ID without parsing HTML via the REST API?

Hello!

I was working with the Confluence Cloud macro API, specifically /content/{id}/history/{version}/macro/id/{macroId}, and noticed the API needs an ID that is automatically generated per macro+page. The macro does appear in the page’s body.storage but as I understand it, backing storage formats may change and parsing HTML (e.g., <ac:structured-macro ...>) is not a reliable approach.

Am I missing something here? Is there a supported way to enumerate/retrieve macro IDs and/or macro content on a given page?

Thanks for any tips in advance!

Hi @RafaelRivera ,

From within the macro iframe, you use the context API to call AP.context.getContext() which will return an object that includes the macro ID. Calling AP.context.getToken() will return a token with the same info in it and this token is designed for sending to your app server which can then extract the macro ID.

Regards,
Dugald

Thanks for the response @dmorrow. I’m just using the native Page Properties macro (for example) via the normal Confluence Cloud page editor. It sounds like getting the ID externally via REST is not really possible then?

Hi @RafaelRivera ,

If you’re only using the REST API, then I think the simplest approach is to retrieve the page in ADF format with https://your-domain.atlassian.net/wiki/api/v2/pages/{pageId}?body-format=atlas_doc_format and then parse the the ADF, pulling out the macroId value, although I don’t know if the ADF format of the Page Properties macro is documented and thereforew a supported API.

Regards,
Dugald

Thanks @dmorrow, that’s a much cleaner solution!