I am working with Automation and web request action. The first step is below:
GET https://{site}/wiki/api/v2/pages?spaceid={spaceid}&title={title}&body-format=storage
I then store {{webResponse.body.results.body.storage.value}} in variable {{content}} and log it.
Next, I use below:
PUT https://{site}/wiki/api/v2/pages/{pageid}
{
"id": "{{webResponse.body.results.id}}",
"status": "current",
"title": "{{webResponse.body.results.title}}",
"body": { "representation": "storage", "value": "{{content}}" },
"version": { "number": {{#increment}}{{webResponse.body.results.version.number}}{{/}}, "message": "" }
}There appears to be a problem with me passing back in {{content}}. Unfortunately, while this works if the page is super simple (just text), anything more complicated like elements or pictures causes the below:
Error publishing web request. Response HTTP status:
Error response HTTP body:
{"errors":[{"status":400,"code":"INVALID_MESSAGE","title":"Invalid message","detail":null}]}
The main idea is that I can change the title and append more information to the page, i.e. {{content}} {{issue.summary}}. However, I cannot get this first part to function correctly. I am basing this process on the details provided here:
https://community.atlassian.com/t5/Automation-articles/Jira-Automation-Updating-a-Confluence-page-with-information-from/ba-p/2660113
UPDATE: I believe I found one of the problems! If the {{content}} contains any " without escaping them first, it just won't work. So to fix, I need to figure out a way to do a regex replacement.
UPDATE2: Use replace("\"", "\\\"") to fix the issue. Everything's working now, I could almost cry!
UPDATE3: I believe the proper way to address the problem is to use .jsonEncode so it will properly handle any chars that need escaping.