Can I insert the History macro through REST API call?
Asked by Krishna Chaitanya M:

Hi,

We are creating a page "B" on a button click from a HTML macro on Page "A". Now while creating page B using an Ajax call from Page A, we would also like to enable the History macro at the bottom of Page B through the ajax call. Is this possible?

Thanks,

KC


Answers:
author: Stephen Sifers
body: Hello KC,

Using the REST API does allow for a lot of adaptability within the product. Ideally, you're going to want to create the page via the API you will include the page info via the storage format. The storage format does allow for adding in macros. Additional information on the storage formats can be found at [Confluence Storage Format](https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html) along with the formatting of the [Change-History Macro](https://confluence.atlassian.com/doc/change-history-macro-154632795.html).

I hope this provides guidance and you're able to include macros within your API calls on page creation within Confluence.

Regards,  
Stephen Sifers

comments: author: Krishna Chaitanya M
body: Thanks for the Answer Sifers.

When I insert a Change History macro on a page and check the Storage Format by clicking ... I am seeing few tags like ac:name="change-history" and a macro id. I then inserted a HTML macro on a page and pasted what ever content I found from Storage Format but that doesn't display the history macro. Do we need to send these through an API call, only then will the macro be enabled?


author: Stephen Sifers
body: Hello again KC,

I was able to create a page within Confluence 6.14 using the REST API endpoint of [POST /rest/api/content](https://docs.atlassian.com/ConfluenceServer/rest/6.15.1/#api/content-createContent). I confirmed this endpoint works with a macro within the storage value of the JSON payload.

Here is an example of what I used to create a page with the History Macro within:

```
curl -v -u username:password -X POST -H 'Content-Type: application/json' -d '{"id":"1231235","type":"page","title":"History Macro","space":{"key":"SPACEKEY"},"body":{"storage":{"value":"<p>History macro test</p><p><ac:structured-macro ac:name=\"change-history\" ac:schema-version=\"1\" ac:macro-id=\"360a0d80-082e-4c82-9ee5-0aac5b72f828\" /></p>","representation":"storage"}}}' http://confluence.server.com:8080/rest/api/content
```

Please give this a try and let us know if you're able to create a Confluence page.

Regards,  
Stephen Sifers


author: Krishna Chaitanya M
body: Thanks Stephen, it worked, had to remove the ID.


author: Stefan Mueller
body: How do you run the command?

Any change to run it within the HTML Macro and use the username and password of the logged-in user?


author: naveenkumar_dp
body: Hi Stefan,

I tried with the above command it did't worked in the cloud confluence.

Can you please help me to insert the macro to cloud confluence page.


author: Andrew Tyson
body: The XHTML fragment needs to be as follows:

    <ac:structured-macro ac:name="iframe" ac:schema-version="1" ac:macro-id="f3b89c73-0096-409c-84fa-0158bf4e0f4f" xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:acxhtml="http://www.atlassian.com/schema/confluence/4/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/">    <ac:parameter ac:name="src">        <ri:url ri:value="https://example.com"/>    </ac:parameter>    <ac:parameter ac:name="width">100%</ac:parameter>    <ac:parameter ac:name="height">750</ac:parameter>    <ac:rich-text-body>        <p>            <br/>        </p>    </ac:rich-text-body></ac:structured-macro>


author: Andrew Tyson
body: Hi [@Stephen Sifers](/t5/user/viewprofilepage/user-id/2145523)

I have a similar requirement to Krishna in that I want to use the REST API to create a new page with the IFrame macro embedded and referring to an external site (i.e. the macro documented in <https://confluence.atlassian.com/confcloud/iframe-macro-950276528.html>).

Where would I be able to find the reference for the IFrame macro (assuming that this can be done)?

Thanks and regards,

Andrew

comments: author: Andrew Tyson
body: The following REST API script creates a new page with the IFrame macro:

```
curl -u <username>:<password> -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"A Test Page", "space":{"key":"SPACE"}, "ancestors" : [ { "id": "115328548" } ],"body":{"storage":{"value":"<h1>IFrame Macro Test</h1><p>Foo Bar Blah</p><p><ac:structured-macro ac:schema-version=\"1\" ac:name=\"iframe\"><ac:parameter ac:name=\"URL\">https://www.foo.com</ac:parameter><ac:parameter ac:name=\"Width\">100%</ac:parameter><ac:default-parameter>https://www.foo.com</ac:default-parameter></ac:structured-macro></p>","representation":"storage"}}}' https://localhost:8080/confluence/rest/api/content | python -mjson.tool;
```

However, the parameters like URL are not be ing set. Any suggestions would be gratefully received.

Thanks and regards,  
Andrew


Tags: api

history

html-macro