Skip to content

Instantly share code, notes, and snippets.

@frodoslaw
Forked from licenseplated/update_wiki.py
Created April 25, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frodoslaw/a3e777e47b6f558abaf9bd2062d6c3c8 to your computer and use it in GitHub Desktop.
Save frodoslaw/a3e777e47b6f558abaf9bd2062d6c3c8 to your computer and use it in GitHub Desktop.
Snippet: Confluence page updates via API
import json
import requests
BASE_URL = 'http://localhost/wiki/'
AUTH_USER = 'user'
AUTH_PASS = 'password123!'
POST_ID = 1234
def update_wiki():
ss = requests.Session()
ss.post(BASE_URL + '/dologin.action', data = { 'os_username': AUTH_USER, 'os_password': AUTH_PASS, 'login': 'Log+in', 'os_destination': '' })
metadata = ss.get('{}/rest/api/content/{}'.format(BASE_URL, POST_ID)).json()
post_title = metadata['title']
post_space = metadata['space']['key']
post_version = metadata['version']['number']
content = ss.get('{}/rest/api/content/{}?expand=body.storage'.format(BASE_URL, POST_ID)).json()
post_content = content['body']['storage']['value']
#
# Do stuff here with post_content
#
update_body = {
'id': POST_ID,
'type': 'page',
'title': post_title,
'space': {
'key': post_space
},
'body': {
'storage': {
'value': post_content,
'representation': 'storage'
}
},
'version': {
'number': int(post_version) + 1
}
}
resp = ss.put('{}/rest/api/content/{}'.format(BASE_URL, POST_ID), json=update_body)
if resp.status_code == 200:
print 'OK'
else:
print resp.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment