Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can I insert the History macro through REST API call?

Krishna Chaitanya M March 21, 2019

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

3 answers

1 accepted

1 vote
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2019

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 along with the formatting of the Change-History Macro.

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

Regards,
Stephen Sifers  

Krishna Chaitanya M March 28, 2019

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?

Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 28, 2019

Hello again KC,

I was able to create a page within Confluence 6.14 using the REST API endpoint of POST /rest/api/content. 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

Krishna Chaitanya M March 29, 2019

Thanks Stephen, it worked, had to remove the ID.

Stefan Mueller November 3, 2019

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?

naveenkumar_dp December 16, 2019

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.

Like NPO Testrapportages likes this
0 votes
Andrew Tyson April 12, 2020

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>
0 votes
Andrew Tyson April 10, 2020

Hi  @Stephen Sifers 

 

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

Andrew Tyson April 11, 2020

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 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events