Update Page Via Rest, "Expander" macro is "goofed up" during edit
Asked by Larry Schapker:

Hello Everyone,

I've been using a "python wrapper" of the Confluence REST APIs with some success. I'm able to create and update pages and add attachments. I'm attempting to update an existing page by adding a "expand" macro to the HTML.

My use case is:

Run a script that creates and attaches a bunch of attachments to a page (i.e. a template), and then I manually add information to the page rounding out the analysis.

When I add the macro via REST, the macro functions properly, but is "goofed up" when I attempt to edit the page via the UI.

The HTML I am adding to the page via REST :

```
<div id="expander-432012860"
class="expand-container">
<div id="expander-control-432012860"
class="expand-control">
<span class="expand-control-icon icon">&nbsp;</span>
<span class="expand-control-text">Expand Title</span>
</div>
<div id="expander-content-432012860"
class="expand-content expand-hidden">
<p>This is the &quot;Expand Body&quot;</p>
</div>
</div>
```

I think I understand the number portion is a random value. When manually creating a page with an expander, I see the IDs but cannot find the number portion in any other part of the HTML document.

if I "View source" of the newly updated page, I find:

```
<div class="expand-container">
<div class="expand-control">
<span class="expand-control-icon icon">&nbsp;</span>
<span class="expand-control-text">Expand Title</span>
</div>
<div class="expand-content expand-hidden">
<p>This is the &quot;Expand Body&quot;</p>
</div>
</div>
```

I presume the lack of "id"s are causing the issue for the UI editor.

What am I doing wrong?  

Thanks in advance!

Larry Schapker


Answers:
author: Davin Studer
body: You need to populate the page with the expected storage format for an expand macro ... not the html that is output by the macro. The storage format for an expand macro looks like this.

```
<ac:structured-macro ac:name="expand" ac:schema-version="1">
    <ac:parameter ac:name="title">The expander text...</ac:parameter>
    <ac:rich-text-body>
        <p>The stuff inside the expand macro.</p>
    </ac:rich-text-body>
</ac:structured-macro>
```

You can get this yourself a couple of ways. You can get the [Confluence Source Editor](https://marketplace.atlassian.com/apps/1210722/confluence-source-editor?hosting=server&tab=overview) from the Marketplace. Or when you are in page view mode click on the ellipsis menu and select "View Storage Format".

comments: author: Larry Schapker
body: Thank you Davin!  

This does work, but (and there always seems to be one \<grin\>) do you know if there is any documentation given somewhere for the macros in general? My environment seems to be fairly locked down and I cannot get access to "Confluence Source Editor" (and I'm not an admin).  

Thanks again!


author: Davin Studer
body: Then the easiest thing would be to mock-up the page the way you would like to see it. Then in page view mode use the ellipsis menu and select "View Storage Format".


author: Larry Schapker
body: Thank you Davin. From what I can tell. the "View Storage Format" is only available to "admins" (of which I am not).

You **have** provided me with something to "sink my teeth into" (which was something I was unable to find Googling). I think I have found some info on this page (<https://confluence.atlassian.com/doc/macros-139387.html>), but it will most likely be a "Trial and error" situation.

Thanks again!


author: Davin Studer
body: Maybe you could reach out to your sys admin and see if they will let you create a personal space. By default you are an admin of your personal space.


Tags: confluence-server

macro

server