I need to update the body and sometimes title also of wiki page in Confluence. For simplicity, let's assume I only need to update its body. I'm unable to do that. I'm trying to update a wiki page and can't. It either returns `200 ok` but really the pages don't get updated or it returns `400 the error "the page with the same title already exists".
AUTH = (config.USERNAME, config.PASSWORD) HEADERS = ({"Content-Type": "application/json", "Accept": "application/json"}) wiki_page_id = 123 new_version = vrs + 1 # vrs being the current version is retrieved from the API page_data = {"id": wiki_page_id, "type": "page", "title": "some title", "ancestors": [{"id": pp_id}], "space": {"key": config.SPACE_NAME},"body":{"storage": { "value": "new body", "representation": "storage"}}, "version": {"number": str(new_version)}} url1 = my_confluence_base_url + "/wiki/rest/api/content" # url2 = my_confluence_base_url + "/confluence/rest/api/content" r1 = requests.put("{}/{}".format(url1, wiki_page_id), data=json.dumps(page_data), auth=AUTH, headers=HEADERS) # r2 = requests.put("{}/{}".format(url2, wiki_page_id), data=json.dumps(page_data), auth=AUTH, headers=HEADERS)
When I use url1 it returns 200 but a wiki page isn't get updated.
When I use url2 it returns 400 with the error "a page with the same title already exists". When I remove the parameter "title", it says "you should provide the parameter title"
How to make that work? Which url should I use?
Community moderators have prevented the ability to post new answers.
Have you tried following the specific example that is provided in the rest documentation?
curl -u admin:admin -X PUT -H 'Content-Type: application/json' -d'{"id":"3604482","type":"page","title":"new page","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is the updated text for the new page</p>","representation":"storage"}},"version":{"number":2}}' http://localhost:8080/confluence/rest/api/content/3604482 | python -mjson.tool
I know that this is a shell curl command, but it should give you a pretty good indication of what to pass into the requests call.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.