It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Confluence Rest API Maintaining Macros After View Conversion Edited

Cody Cuellar Sep 14, 2017

Hi, I built a Python module that downloads the HTML from a confluence page, modifies it, and then updates the page. Currently what I'm doing:

I first fetch the storage JSON content by doing a 'get' request using Python requests module from the following link:

{SERVER_URL}/rest/api/content/{PAGE_ID}?expand=body.storage

From there I do a post request with this JSON data to the link:

{SERVER_URL}/rest/api/contentbody/convert/view

 The resulting data is standard HTML which I then modify, convert back to storage format with another post request to:

{SERVER_URL}/rest/api/contentbody/convert/storage

And from there I re-publish the page with a put request containing all the updated JSON information.

Almost everything works, and when just viewing the page normally, everything looks correct. The only problem is certain macros - although displaying correctly in view mode - are not converted correctly back to storage format, so when modifying the page in edit mode, things like info macros do not visually show in the editor. Instead of showing the actual info box, it looks like regualar bold text until I close the editor.

Is this normal behavior for the conversion? Is there a way to republish the page and keep all macros exactly as they would appear if added in the editor or should my approach be to just figure out how to modify the storage format directly without converting it to view HTML?

Here's some code snippets for reference --

Original storage content:

<ac:structured-macro ac:name="info" ac:schema-version="1" ac:macro-id="e5767804-bcd7-449d-a3c6-d8b56a17222e">
<ac:rich-text-body><strong>INFO Text Here</strong>
</ac:rich-text-body>
</ac:structured-macro> 

 Original converted HTML view:

<div class="confluence-information-macro confluence-information-macro-information conf-macro output-block" data-hasbody="true" data-macro-name="info">
<span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span>
<div class="confluence-information-macro-body"><strong>INFO Text Here</strong></div>
</div>

Converted back to storage:

<div class="confluence-information-macroconfluence-information-macro-information conf-macro output-block">
<span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span>
<div class="confluence-information-macro-body"><strong>INFO Text Here</strong></div>
</div>

Any guidance would be greatly appreciated, thanks! 

1 answer

0 votes
Stephen Deutsch Sep 15, 2017

I would say your best bet is to try to modify the storage format directly. I'm surprised that you can even change view mode back to storage, as there's nothing in the view code that allows Confluence to tell what the original macro looked like. This means that you'll never be able to get the original code from re-conversion, so changing the storage format would be the way to go.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

1,293 views 8 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you