Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify wiki page (Confluence) programmatically

I'd like to modify a wiki page (Confluence by Atlassian - JIRA editors) programmatically (in python). What I tried so far is to simulate user behaviour:

  1. click on Edit button
  2. change content of a textarea input
  3. submit changes with Save button

Part 1 is ok since I have the URL corresponding to an edit of the page, part 2 (retrieval of the page and modification) is ok too, but I don't know how to achieve step 3... I'm using urllib2.

Thanks for your help !!

EDIT: XML-RPC is indeed the solution, this example does exactly what I want !

like image 470
Emmanuel Avatar asked Feb 12 '26 05:02

Emmanuel


1 Answers

# write to a confluence page
import xmlrpclib

CONFLUENCE_URL = "https://intranet.example.com/confluence/rpc/xmlrpc" 
CONFLUENCE_LOGIN = "a confluence username here"
CONFLUENCE_PASSWORD = "confluence pwd for username"

# get this from the page url while editing
# e.g. ../editpage.action?pageId=132350005 <-- here
PAGE_ID = "132350005" 
client = xmlrpclib.Server(CONFLUENCE_URL, verbose = 0)
auth_token = client.confluence2.login(CONFLUENCE_LOGIN, CONFLUENCE_PASSWORD)
page = client.confluence2.getPage(auth_token, PAGE_ID)

# and write the new contents
page['content'] = "!!!your content here!!!"

result = client.confluence2.storePage(auth_token, page)
client.confluence2.logout(auth_token)

Note that confluence modifies your html code when you do this. It strips out scripts, styles and sometimes title attributes on elements for example. In order to get that stuff back in you then need to use their macro code.

Easiest way to do this is to edit the page in confluence and make it look like you want and then grab the page and do a print page['content'] to see what magical new stuff the atlassian people have decided to do to standard html.

like image 72
demented hedgehog Avatar answered Feb 14 '26 19:02

demented hedgehog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!