I have a workflow where a user passes in a link to a Confluence page and I try to replace a string in the HTML with an updated string. I get the page ID, create a Confluence connection, and then my code looks like this:
page = confluence_connection.get_page_by_id(id, expand='space,history,body,body.view,version,ancestors', status=None, version=None)
content = page['body']['view']['value']
new_content = content.replace(old_string, new_string)
confluence_connection.update_page(page_id, page['title'], new_content)
The target string I'm replacing is something like "This link hasn't been updated" and the new string is a new link. On some pages, the update works. On others, after the update, I get the message:
We’ve hit a snag
The issue should resolve on its own, but if it keeps happening, ask your admin to contact our support team and give them:
- The URL of this page
- The code associated with this error: an2bkm
Refresh page
I did notice that after the update for the pages that fail, there's HTML in page['body']['storage']['value'] but there's nothing in page['body']['view']['value']. Nothing immediately jumps out at me as being different between the pages that work and those that don't. I'm wondering if the expand params I'm passing into get_page are wrong, I need to add some additional value to the update_page call, or if I need to pass something slightly different for new_content.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.