How do I get the data from collapsible sections in a confluence page?
Do you mean to get the content of the Expand Macro or what exactly do you mean by “collapsible sections in a confluence page”?
Thanks for the quick reply Sven, so I have tons of expand macro in my page and I need to fetch the details inside them
If you know the macro ids you can use this REST API.
Another way would be to parse the storage format of the page yourself (e.g. using Jsoup). The storage format of expand macros looks like this:
<ac:structured-macro ac:name="expand">
<ac:parameter ac:name="title">Expand me...</ac:parameter>
<ac:rich-text-body>
<p>This text is hidden until you expand the section.</p>
</ac:rich-text-body>
</ac:structured-macro>
It may be useful for you to have a look at this question where they are doing something similar (they are searching for macros with the name “dihk-taskassign-macro” instead of “expand”).
I’ll try that. Thanks a lot Sven.
hey good folks, I tried this to fetch the details from macro, “https://your-domain.atlassian.net/wiki/rest/api/content/{id}/history/{version}/macro/id/{macroId}”. Somehow I’m only getting the macro title only. I’ve even given ?expand=body.storage in the URL
Oops - for some reason I assumed you were on Server. To avoid having people like me make this mistake make sure you post in the Confluence Cloud category next time.
So the link to the REST API reference that I posted is for Server, for Cloud you’ll want to look here.
I tried the API on my Cloud instance it seems to work just fine:
Are you sure you have specified pageVersion, pageId and macroId correctly?
No no it is for server only. Yes I did give proper macro id, also if I do a ?expand=body.view for the whole page, I get a dump of html tables and all that, apparently my macros have tables, how do I exclude it?