How can I append a string to a wiki page on confluence?

I'd like to progremmatically append a string to the end of a wiki page/article on our wiki (using Java from play framework).

I tried going though the APIs but I didn't find any relevant methods to do so.

What should I do to acheive this?

3 answers

1 accepted

You can do it like this:

//login to Confluence
            String token = service.login(user, passwd);
            
            // get page
            RemotePage page = service.getPage(token, "spaceKey", "page title");
            page.setContent(page.getContent() + "<p>append here</p>");
            
            //define the update options
            RemotePageUpdateOptions opt = new RemotePageUpdateOptions();
            opt.setVersionComment("new update");
            opt.setMinorEdit(true);
            
            // make some changes
            RemotePage updated = new RemotePage();
            updated = service.updatePage(token, page, opt);

            System.out.println("Content updated");
 
            System.out.println("content: " + updated.getContent()
            		+ "\nversion: " + updated.getVersion()
            		);

For more information:

https://developer.atlassian.com/display/CONFDEV/Confluence+XML-RPC+and+SOAP+APIs

https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Data+Objects

https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Methods

I made something similar (without the API function - raw xml) but it seems to not work when I try to insert html elements like <br /> - how can I update the pages with some basic html (specificly line breaks). - edit: I fixed it, the parser thought that it was a child node - though it shouldn't be.

For those that just want to add text to pages (not do the programming part :) ), then modifyPage from Confluence Command Line Interface will do that. Use content to add text to the start of a page and content2 to add text to the end of the page.

And how can I do it programmatically? (an example or direction will be appreciated).

You can add a conflucense listener, https://developer.atlassian.com/display/CONFDEV/Event+Listener+Module

And when detecting the page is created/updated, and then you can update the content of the page by appending the string, please refer to ContentEntityObject class in conflucence api, it allows to get and set the body content. You can search the class from https://docs.atlassian.com/atlassian-confluence/5.1.3/

I don't need a listener, I want to append the string from a remote server on his call. When my remote server wants to append a string, then is when I want to trigger the API call, but I couldn't find a proper example to do so.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Friday in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

253 views 11 10
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you