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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Can I insert the History macro through REST API call?

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

0 votes
Answer accepted

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  

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?

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

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

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?

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.

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

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 

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>

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

480 views 24 9
Join discussion

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